DVA-C02 Question 372
Single answerYou are developing a serverless application using AWS Lambda and need to ensure that your logs are structured to allow for efficient querying and debugging. Which approach should you take to implement structured logging in your application?
- A
Use a logging library to output logs in JSON format and send them to Amazon CloudWatch Logs.
- B
Write raw text logs directly to Amazon S3 for later analysis with Amazon Athena.
- C
Log data in plain text format and add custom metadata by manually parsing logs when needed.
- D
Use AWS X-Ray to automatically structure all your logs without requiring any additional configuration.
Show answer and explanation
Correct answer: A
Explanation
Structured logging involves formatting logs in a machine-readable structure like JSON, which makes it easier to query, analyze, and debug logs. Using a logging library to emit JSON-formatted logs and integrating with Amazon CloudWatch Logs is a best practice for serverless applications on AWS.
- A. Correct.
Correct. Using a logging library to output logs in JSON format ensures logs are structured and machine-readable, enabling efficient querying and debugging in CloudWatch Logs.
- B. Incorrect.
Incorrect. While Amazon S3 and Athena can be used for log analysis, this approach is inefficient for real-time debugging and querying compared to structured logging in CloudWatch.
- C. Incorrect.
Incorrect. Logging in plain text and manually parsing metadata is error-prone and inefficient, especially in large-scale applications.
- D. Incorrect.
Incorrect. AWS X-Ray is used for distributed tracing but does not automatically structure application logs for querying and debugging.