DVA-C02 Question 371
Select 3You are developing a serverless application on AWS and need to ensure logs are structured in a way that makes them easily searchable and filterable in Amazon CloudWatch Logs. Which of the following practices should you implement?
- A
Log data in a JSON format with consistent keys across all logs.
- B
Write logs in plain text with minimal formatting for simplicity.
- C
Use a logging library that supports structured logging, such as AWS SDK logging utilities.
- D
Include a timestamp and unique request ID in every log entry.
- E
Aggregate all logs into a single large log file for simplicity.
Show answer and explanation
Correct answers: A, C, D
Explanation
Structured logging involves formatting logs in a way that makes them machine-readable and easy to analyze. JSON is a common format for structured logging, and using logging libraries helps maintain consistency. Including contextual metadata like timestamps and request IDs further enhances log usability. Plain text or aggregated logs lack structure and can complicate filtering and analysis in tools like CloudWatch Logs Insights.
- A. Correct.
Correct: JSON is a structured format that makes logs easier to parse, search, and filter in tools like CloudWatch Logs Insights.
- B. Incorrect.
Incorrect: Plain text logs lack structure, making them harder to query and analyze effectively.
- C. Correct.
Correct: Logging libraries that support structured logging help you consistently format and emit logs with relevant metadata.
- D. Correct.
Correct: Including timestamps and request IDs adds important context to logs, making it easier to trace specific events and debug issues.
- E. Incorrect.
Incorrect: Aggregating all logs into a single file reduces clarity, as it becomes harder to analyze data or search for specific entries.