The supported logging levels are ERROR, WARN, INFO, DEBUG, and TRACE. Logback does not have a FATAL level. In Spring Boot, the FATAL level is mapped to ERROR and by default, ERROR-level, WARN-level, and INFO-level messages are logged.
You can also enable a “debug” mode by starting your application with a --debug flag. For example, java -jar myapp.jar --debug, or specifying debug=true in your application.properties file. When the debug mode is enabled, a selection of core loggers (embedded container, Hibernate, and Spring Boot) are configured to output more information. Enabling the debug mode does not configure your application to log all messages with DEBUG level.
Alternatively, you can enable a “trace” mode by starting your application with a --trace flag (or trace=true in your application.properties file). Doing so enables trace logging for a selection of core loggers (embedded container, Hibernate schema generation, and the whole Spring portfolio).
Enabling the trace mode does not configure your application to log all messages with TRACE level.
By default, Spring Boot logs only to the console and does not write to log files. If you want to write to log files in addition to the console output, you need to set a logging.file.name or logging.file.path property in your application.properties file.
The following table shows how the logging.* properties can be used together:
|(none)||(none)||Console only logging.|
|Specific file||(none)||my.log||Writes to the specified log file. Names can be an exact location or relative to the current directory.|
|(none)||Specific directory||/var/log||Writes spring.log to the specified directory. Names can be an exact location or relative to the current directory.|
By default, log files rotate when they reach 10 MB and, as with console output, ERROR-level, WARN-level, and INFO-level messages are logged by default. Size limits can be changed using the logging.file.max-size property. Rotated log files of the last 7 days are kept by default unless the
logging.file.max-history property has been set. The total size of log archives can be capped using logging.file.total-size-cap property. When the total size of log archives exceeds that threshold, backups will be deleted. To force log archive cleanup on application startup, set the logging.file.clean-history-on-start property.
All the supported logging systems can have the logger levels set in the application.properties file by using logging.level.<logger-name>=<level> where level is one of TRACE, DEBUG,
INFO, WARN, ERROR, FATAL, or OFF. The root logger can be configured by using logging.level.root. The root logger logs messages for all classes in application.
The following example shows potential logging settings in the application.properties file:
logging.level.root=warn (set’s the logging level for all packages)
You can force Spring Boot to disable Spring Boot’s logging configuration entirely by setting the value of org.springframework.boot.logging.LoggingSystem property to none.
A more flexible and powerful way to configure Spring Boot logging, instead of setting the properties in application.properties file, is to use a logback-spring.xml file that is stored in the CLASSPATH. fastCode’s generated applications use this mechanism.
In the fastCode generated application, this file is stored in the resources folder. You can set any location for the logback-spring.xml config file by using the "logging.config" property.
The fastCode generated application’s logback-spring.xml file specifies that in “dev” profile, messages with ERROR, WARN, INFO, DEBUG levels should be logged to the console, where in the “prod” profile, messages with ERROR and WARN levels should be logged to the rolling log files in the logs/ directory.
Updated over 1 year ago