如何在 spring-boot 记录器名称中不缩写源 class 名称?
How to not-abbreviate the source class name in spriing-boot's loggger name?
当我 运行 启动一个 spring 应用程序时,它显示以下日志:
2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter' 到:[/*]
记录器名称的缩写如下:
org.springframework.boot.context.embedded.FilterRegistrationBean
如何显示完整的来源 class 名称?
谢谢!
默认情况下 Spring 引导使用 Logback logging. You can change the configuration by putting a logback.xml file in your class path. They have a default base.xml which defines the overall configuration and includes their defaults.xml 文件。由于定义日志模式的位置,您需要创建一个文件,其中复制了一些项目。这是我创建的 logback.xml 的示例:
<configuration>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%C){cyan} %clr(:){faint} %m%n%wex"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
下面是使用此配置的日志消息示例:
2015-06-17 09:02:06.511 INFO 18816 --- [ main] org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
如果需要,您可以进一步调整模式。请参阅 this page 和 PatternLayout 部分以了解可能包含的项目。
您还可以根据 logging documentation 使用其他日志记录实现,然后根据需要进行配置。
更新:从 Spring 引导版本 1.3.0 开始(截至本次编辑尚未发布)您可以使用 logging.pattern.console 和 logging.pattern.file 属性来设置默认模式登录配置。请参阅其文档中的示例属性文件 here。注意:此 link 可能会更改,因为它指向构建 SNAPSHOT 文档。
当我 运行 启动一个 spring 应用程序时,它显示以下日志:
2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter' 到:[/*]
记录器名称的缩写如下: org.springframework.boot.context.embedded.FilterRegistrationBean
如何显示完整的来源 class 名称?
谢谢!
默认情况下 Spring 引导使用 Logback logging. You can change the configuration by putting a logback.xml file in your class path. They have a default base.xml which defines the overall configuration and includes their defaults.xml 文件。由于定义日志模式的位置,您需要创建一个文件,其中复制了一些项目。这是我创建的 logback.xml 的示例:
<configuration>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%C){cyan} %clr(:){faint} %m%n%wex"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
下面是使用此配置的日志消息示例:
2015-06-17 09:02:06.511 INFO 18816 --- [ main] org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
如果需要,您可以进一步调整模式。请参阅 this page 和 PatternLayout 部分以了解可能包含的项目。
您还可以根据 logging documentation 使用其他日志记录实现,然后根据需要进行配置。
更新:从 Spring 引导版本 1.3.0 开始(截至本次编辑尚未发布)您可以使用 logging.pattern.console 和 logging.pattern.file 属性来设置默认模式登录配置。请参阅其文档中的示例属性文件 here。注意:此 link 可能会更改,因为它指向构建 SNAPSHOT 文档。