工作生活

SpringBoot_10 控制日志

2019-07-06  本文已影响0人  o______o

日志格式


Spring Boot的默认日志输出类似于以下示例:

2014-03-05 10:57:51.112  INFO 45469 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.52
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 completed in 1358 ms
2014-03-05 10:57:51.698  INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2014-03-05 10:57:51.702  INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

输出以下类别:

启用“调试”模式


$ java -jar myapp.jar --debug

你也可以在你的application.properties文件中指定debug=true

文件输出


默认情况下,Spring Boot仅记录到控制台,不会写入日志文件。如果除了控制台输出之外还要编写日志文件,则需要设置 logging.file或logging.path属性(例如,在您的application.properties属性文件中)。

下表显示了如何一起使用这些属性:

logging.file logging.path Example Description
(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.

日志文件在达到10 MB时会轮换,与控制台输出一样,默认情况下会记录ERROR-level, WARN-level和INFO-level消息。可以使用logging.file.max-size属性更改大小限制

日志级别


以下示例显示了的日志记录设置application.properties

logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

其他方式


上一篇下一篇

猜你喜欢

热点阅读