When to use the different log levels
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Logging is a critical aspect of software development. It provides transparency into the application’s runtime behavior and helps in understanding how an application is functioning or why it might be failing. Choosing the correct log level when writing logs can significantly aid in troubleshooting and monitoring without overwhelming the logging system or the operators trying to make sense of the logs. Here, we'll explore when to use various log levels, primarily focusing on the widely accepted log levels: DEBUG, INFO, WARN, ERROR, and FATAL.
Debug
The DEBUG level is used to output detailed informational events useful in debugging an application. These events are mostly used by developers to understand the application flow or to check the values of variables.
When to use:
- During development to trace the program flow and internal state.
- To record detailed state information that might be needed to diagnose issues, especially those which are hard to replicate.
Example:
Info
The INFO level is used to log messages that are informational in nature and highlight the progress of the application at a coarse-grained level.
When to use:
- For recording execution milestones or important state changes in the application.
- To trace what actions have been taken, without the detail needed only for debugging.
Example:
Warn
WARN log level indicates a potential issue or a situation that could possibly lead to an error, but one that does not stop the application from functioning.
When to use:
- When something unexpected happens, but the application can continue running.
- To record missing, faulty, or suboptimal data where defaults have been used as a fallback.
Example:
Error
The ERROR level is appropriate for logging errors which might still allow the application to continue running, but which indicate problems that should be addressed.
When to use:
- When an operation could not be completed as expected due to an error condition, but the application or a critical thread continues to run.
- For any issue that requires intervention or further investigation to resolve.
Example:
Fatal
The FATAL log level signifies very severe error events that lead possibly to the termination of the application execution.
When to use:
- When a critical error has occurred, and the process must be shut down.
- To log events where a safe continued operation is no longer possible.
Example:
Summarizing the Log Levels
Here is a concise table summarizing when to use each log level:
| Log Level | Usage Scenario | Example |
| DEBUG | For detailed debugging and development. | logger.debug("Initiating module X."); |
| INFO | For important runtime events tracking. | logger.info("Application launched successfully."); |
| WARN | For potentially harmful situations. | logger.warn("Deprecated API used by a module."); |
| ERROR | For error events that might allow the application to continue running. | logger.error("Module X failed to load."); |
| FATAL | For very severe error events that will presumably lead the application to abort. | logger.fatal("Critical services failed."); |
Additional Considerations
- Performance Issues: Logging excessively at a detailed level like DEBUG can lead to performance degradation and large log files.
- Security and Privacy: Ensure that log entries do not capture sensitive information. Use secure, masked, or tokenized placeholders where necessary.
- Environment-specific Logging: Sometimes it is advisable to configure log levels differently for different environments; for example, DEBUG might be enabled in a development environment, but only WARN and above enabled in production.
By understanding and intelligently utilizing these log levels, developers can ensure their application logs are helpful, manageable, and appropriate for the scenarios in which they are operating.
Related reading
- When to use writer.flush in Tensorboard
- Where are AWS CodeDeploy Deployment logs found?
- Where are Docker images stored on the host machine?
- Where are helm charts stored locally?
- Where are the Kubernetes kubelet logs located?
- Where can I log debug Velocity Template Language VTL in AWS AppSync?
- Where can I find descriptions of Prometheus metrics?
- Where can I find php.ini?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.