Spring Boot uses Commons Logging for all internal logging but leaves the underlying log
implementation open. Default configurations are provided for Java Util Logging, Log4J2, and
Logback. In each case, loggers are pre-configured to use console output with optional file output
also available.
By default, if you use the “Starters”, Logback is used for logging. Appropriate Logback routing is
also included to ensure that dependent libraries that use Java Util Logging, Commons Logging,
Log4J, or SLF4J all work correctly.
1.开启debug模式
The default log configuration echoes messages to the console as they are written. 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.
$ java -jar myapp.jar --debug
2.改颜色:
默认颜色:
Level Color
FATAL Red
ERROR Red
WARN Yellow
INFO Green
DEBUG Green
TRACE Green
Alternatively, you can specify the color or style that should be used by providing it as an option to
the conversion. For example, to make the text yellow, use the following setting:
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
The following colors and styles are supported:
• blue
• cyan
• faint
• green
• magenta
• red
• yellow
3.日志级别配置
logging.level.root=warn
logging.level.org.springframework.web=debug
logging.level.org.hibernate=error
4.日志组级别配置
To help with this, Spring Boot allows you to define logging groups in your Spring Environment. For
example, here’s how you could define a “tomcat” group by adding it to your application.properties:
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
Once defined, you can change the level for all the loggers in the group with a single line:
logging.level.tomcat=TRACE
5.配置文件(基本都是这种方式)
- Logback
logback-spring.xml, logback-spring.groovy, logback.xml, or logback.groovy - Log4j2
log4j2-spring.xml or log4j2.xml
网友评论