Springboot log and springboot log Configuration
1. Logs
The internal log system of Spring Boot uses Commons Logging, but the underlying log implementation is enabled. By default, Java Util Logging, Log4J, Log4J2, and Logback are configured. In each case, console output is configured in advance, or optional file output can be used.
By default, if you use 'Starter POMs ', Logback is used to record logs. To ensure that the dependent libraries using Java Util Logging, Commons Logging, Log4J, or SLF4J work properly, the correct Logback route is also included.
Note: If the list above looks confusing, don't worry. Java has many available log frameworks. Generally, you do not need to change the log dependency, so Spring Boot works well by default.
2. log format
The default log output format of Spring Boot is as follows:
2014-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/
2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization
2014-03-05 10:57:51.698 INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet'
2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: '
The output node (items) is as follows:
1. Date and Time-accurate to milliseconds and easy to sort.
2. Log Level-ERROR, WARN, INFO, DEBUG or TRACE.
3. Process ID.
4. A --- delimiter used to distinguish the beginning of the actual log information.
5. Thread name-included in square brackets (console output may be truncated ).
6. Log name-generally the class name (abbreviation) of the source class ).
7. log information.
3. Console output
The default log configuration will display the log messages back to the console. By default, messages at the ERROR, WARN, and INFO levels are recorded.
4. file output
By default, Spring Boot only records logs to the console and does not write them into log files. If you want to write logs in addition to the output to the console, you need to set the logging. file or logging. path attribute (for example, in your application. properties)
The following table shows how to use logging in combination .*:
Every 10 MB of a log file is rotated (split). As in the console, ERROR, WARN, and INFO information are recorded by default.
5. Log Level
All supported log systems in Spring's Environment (for example, in application. properties. level. * = LEVEL ('level' is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, and OFF.
Example: application. properties
logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR
6. Custom log Configuration
You can activate various log systems by adding appropriate libraries to classpath. Then, in the root directory of classpath (root) or through Spring Environment's logging. the location specified by the config attribute provides an appropriate Configuration file for further customization (note that because the log is initialized before ApplicationContext is created, it is not possible in the @ Configuration file of Spring, use @ PropertySources to control logs. System attributes and common external Spring Boot configuration files ). Based on your log system, the following files will be loaded:
To help customize some other attributes, convert the Envrionment of Spring to the system attributes:
All supported log systems can query system properties when parsing their configuration files. For more information, see the default configuration in the spring-boot.jar.
Note: Java Util Logging has class loading issues when running executable jar. We recommend that you avoid using it whenever possible.