Developing Applications: Logging Approach for 12-Factor App Methodology

Logging Approach for 12-Factor App Methodology

Question

While developing an application following the 12-factor app methodology, which approach should be used in the application for logging?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

D.

The 12-factor app methodology is a set of principles for building modern, scalable, and maintainable applications. One of the factors is logging, which helps developers diagnose and troubleshoot issues in production.

When it comes to logging in the 12-factor app methodology, option C is the recommended approach: "Write the logs buffered to stdout."

Here's why:

  1. Logs are treated as event streams: In the 12-factor app methodology, logs are treated as event streams, which means they should be treated as real-time data instead of a historical record. By writing logs to stdout, they can be easily collected and managed by a log aggregator or other tools.

  2. Logs should not be written to the file system: Writing logs to a file in the application directory (option A) or /var/log (option B) violates the 12-factor app methodology's principle of treating the file system as ephemeral. The file system can change at any time, which means logs can be lost if the application is restarted or moved to a different host.

  3. Buffered logs are more efficient: Writing logs buffered to stdout (option C) means that logs are not written to disk immediately, but are stored in memory and then written in batches. This approach is more efficient than writing logs unbuffered to stdout (option D), which can result in a high I/O load and degrade application performance.

In summary, the recommended approach for logging in the 12-factor app methodology is to write logs buffered to stdout (option C). This approach is more efficient, adheres to the principle of treating the file system as ephemeral, and allows logs to be easily collected and managed by log aggregators and other tools.