Most logging frameworks support the ability to specify a log level or the severity of each log entry that is created. Although the log levels vary depending on the framework used, some common log levels include the following:
- TRACE: Use this level for tracing the code, such as being able to see when execution flow enters and exits specific methods.
- DEBUG: This level records diagnostic details that can be helpful during debugging. It can be used to make note of when certain aspects of the logic are completed successfully. It can also provide details such as executed queries and session information, which can be used in determining the cause of an issue.
- INFO: This level is for logging details about normal operations during the execution of logic. It is common for INFO to be a default log level. It is for useful information that you want to have but typically won't spend much time examining under normal circumstances.
- WARN: When you have a situation in which incorrect behavior takes place, but the application can continue, it can be logged at the Warn level.
- ERROR: Use this level for exceptions and problems that caused an operation to fail.
- FATAL: This level is reserved for the most severe errors, such as those that may cause the shutdown of the system or data corruption.
Logging frameworks typically allow you to configure the level at which logging will take place, such as being able to specify a minimum log level. For example, if the minimum log level is configured as Info, then logging will take place for the log levels of INFO, WARN, ERROR, and FATAL.
A detailed log level, such as TRACE, is not typically used for sustained periods, particularly for a production environment. This is due to the high volume of detailed entries that will be produced, which can degrade performance and excessively use up disk and bandwidth resources. However, when diagnosing an issue, being able to change the log level to DEBUG or TRACE temporarily can provide valuable information.