A developer has deployed a Java application on an Amazon EC2 instance. The application logs details, including multi-line stack traces, to a local file at `/var/log/app/output.log`. The developer has configured the unified Amazon CloudWatch agent on the instance to stream these logs to a CloudWatch Logs log group. However, when viewing the logs in the CloudWatch console, each line of a single Java stack trace appears as a separate log event, making troubleshooting difficult. Which action should the developer take to group each multi-line stack trace into a single log event?
- AModify the CloudWatch Logs log group settings in the AWS Management Console to enable multi-line log detection.
- Configure the `multi_line_start_pattern` parameter in the Amazon CloudWatch agent configuration file to define a regular expression matching the start of each logical log message.Cevap
- CConfigure a CloudWatch metric filter with a regular expression that aggregates multiple incoming log streams based on a timeout value.
- DAttach an IAM policy to the EC2 instance role that grants the `logs:PutLogEvents` permission with a condition that enforces multi-line formatting.
Cevap
Configure the `multi_line_start_pattern` parameter in the Amazon CloudWatch agent configuration file to define a regular expression matching the start of each logical log message.
Configuring the `multi_line_start_pattern` parameter in the CloudWatch agent configuration file allows the agent to identify the start of a new log event using a regular expression (e.g., matching a timestamp). Any subsequent lines that do not match the pattern are treated as part of the current log event, ensuring that multi-line stack traces are correctly grouped and ingested as a single event.
Adım Adım Çözüm
Anahtar Kavram
Handling multi-line log events with the CloudWatch Agent configuration
Tahmini Süre:1m 30s