Preface
Spring Boot uses Commons Logging in all internal logs , but the default configuration also provides support for commonly used logs,
such as: Java Util Logging, Log4J, Log4J2 and Logback. Each Logger can be configured to use the console or file to output log content.
Log output format
2016-08-19 10:22:04.233 INFO 7368 --- [ main] com.juzi.AsyncTest : Started AsyncTest in 10.084 seconds (JVM running for 12.545)
The output content elements are as follows:
Console outputTFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
In Spring Boot, ERROR, WARN, and INFO level logs are configured by default to be output to the console.TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
We can switch to DEBUG level in two ways:TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
$ java -jar myapp.jar debug TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
application.properties
debug=true, when this property is set to true, the core Logger (including embedded containers, hibernate, spring) will output more content, but your own application logs will not be output at DEBUG level.
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Colorful OutputTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
If your terminal supports ANSI, setting colored output will make the logs more readable. Supported by setting thespring.output.ansi.enabled parameter in
application.properties.
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Net - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
File OutputTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
The default configuration of Spring Boot will only be output to the console and will not be recorded in a file. However, we usually need to record it in a file when using it in a production environment.TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
To increase file output, you need to configurelogging.file or in
application.properties
logging.pathProperty.
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
logging.file, set the file, which can be an absolute path or a relative path. For example:
logging.file=my.logTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
logging.path, set the directory, the
spring.log file will be created in the directory, and the log content will be written, such as:
logging.path =/var/logTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Level ControlTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
In Spring Boot, you only need to configure it inapplication.properties to complete the level control of logging.
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
logging.level.*=LEVELTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
1.logging.level
: Log level control prefix, * is the package name or Logger name
2.LEVEL: Options TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
Example:
##logging .level.com.juzi=DEBUG com.juziAll classes under the package are output at DEBUG level
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
logging.level.root=WARN The root log is output at WARN level
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Custom log configurationTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Since the log service is generally initialized before the ApplicationContext is created, it does not have to pass Spring configuration file control.TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network Therefore, log control and management can still be well supported through system properties and traditional Spring Boot external configuration files.
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
1.Logback: logback-spring.xml, logback-spring.groovy, logback.xml, logback.groovy logback log configurationTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network##TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
4.JDK (Java Util Logging ): logging.properties
Spring Boot official recommendation is to give priority to the file name with -spring as your log configuration (such as using logback-spring .xml, not logback.xml)
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning NetworkCustomized output format
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning NetworkIn Spring Boot, you can control the output format by configuring the following parameters in
application.properties: TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
1.
: Define the style of output to the console (JDK Logger is not supported)TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
2.
: Define the style of output to the file (JDK Logger is not supported)
The above is the detailed content of Detailed explanation about Spring Boot’s log management. For more information, please follow other related articles on the PHP Chinese website!