The spring boot logging level allow the application to log in different log levels. The spring boot log level is set to INFO by default. The information and above level logs will be shown in the console window or in a log file. The logging level can be modified at the level of the java package or root level.The spring boot log level root will produce all application logs.
The logging level of the spring boot application is set using the logging configuration in the application.properties file. The spring boot logging framework enables a configuration that lets you change the logging level of the application.
Spring Boot also includes a good starting point for logback to customise some of the defaults that you can easily use in the logback.xml file. Logging details can be configured in the xml format with Logback.xml. Logback.xml provides high flexibility to customise logging package, level, pattern, file appender, etc.
Available Logging Levels
There are seven types of logging levels available in the spring boot logging framework. Logging level works as a relative level. If the logging level is set to info, info logs and above level logs will be seen. In this scenario, all INFO, WARN, ERROR, FATAL logs will be seen.
If the logs are not interested in any of the packages, the logging level is set to OFF. Except that package, the logs will be written.
TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
Logging at ROOT Level
Logging at the root level configuration can be extended to the whole application. This logging level would extend to both java packages and jar files. This logs are typically very large in volume. The root level log is usually configured with the WARN level to restrict the logs to be created at the root level.
logging.level.root=WARN logging.level.web=DEBUG logging.level.sql=DEBUG
Logging at Spring Boot Framework Level
Spring boot framework files will be included in the package starting with org.springframework. If the logging level is modified using this package, the logs of the spring boot framework will be displayed at the configured logging level.
Logging at Hibernate Level
The most important logs in the spring boot framework are to debug the hibernate level to understand the execution queries. The generated sql and parameter values are printed using hibernate logs. Setting the hibernate logging level is critical for the spring boot application to match the number of logs and log information.
The first two configurations are set using the Java Persistence API. The configuration below sets the hibernate logging level for printing the generated sql and the parameters. Each parameter will be printed in a separate log.
spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true logging.level.org.hibernate=DEBUG logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql=DEBUG
Logging at Application Package Level
The spring boot application has been created with the custom package name. The logging level can be changed for the application package level. The logs within the custom package will be application for the logging level configuration. For each package name, the logging level may be configured differently. If the logging level is set in the root package, it will be applied to all subpackages.
You can configure the logging level in the Logback configuration file using the logger tag. The name in the logger tag contains the name of the package. The level in the logging tag contains the logging level.
<?xml version="1.0" encoding="UTF-8"?> <configuration> ........... <logger name="com.yawintutor" level="DEBUG" additivity="false"> <appender-ref ref="RollingFile" /> <appender-ref ref="Console" /> </logger> ........... </configuration>
You can set the logging level in various formats. Spring boot framework accepts multiple configuration options, such as application.properties, application.yml, command line argument, log4j.xml, logback.xml. Spring boot supports configuring the logging level using the spring boot logging framework apis.