默认的CONSOLE_LOG_PATTERN用于Spring Boot日志记录,可以在哪里找到它?

huangapple go评论84阅读模式
英文:

What is default CONSOLE_LOG_PATTERN used for Spring Boot logging and where to find it?

问题

Spring Boot参考文档4.6. 自定义日志配置关于表示在控制台上使用的默认日志模式的默认系统属性如下(仅在默认Logback设置下受支持):

  • Spring环境:logging.pattern.console
  • 系统属性:CONSOLE_LOG_PATTERN

我猜想对于所有Spring Boot框架用户来说,默认的日志行外观都很熟悉:

2020-08-04 12:00:00.000  INFO 24568 --- [           main] c.c.MyWonderfulSpringApplication          : The following profiles are active: local

只要我想看看它的外观并从中获得灵感,以定义我的自定义日志模式,我可以在哪里找到当前使用的Spring Boot版本的默认值?

英文:

The Spring Boot reference documentation 4.6. Custom Log Configuration states about the default system properties representing a default logging pattern to use on the console (only supported with the default Logback setup).

  • Spring Environment: logging.pattern.console
  • System Property: CONSOLE_LOG_PATTERN

I guess the default log line look is familiar for all the Spring Boot framework users:

2020-08-04 12:00:00.000  INFO 24568 --- [           main] c.c.MyWonderfulSpringApplication          : The following profiles are active: local

As long as I want to take look on how it looks and get inspired for defining my own one, where can I find this default value for a currently used version of Spring Boot?

答案1

得分: 28

我刚刚发现这个配置可以在Spring Boot项目的DefaultLogbackConfiguration文件中找到:

private static final String CONSOLE_LOG_PATTERN = "%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} "
			+ "%clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} "
			+ "%clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} "
			+ "%clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}";

要查找特定Spring Boot版本的模式,可以选择以下方法之一:

  • 浏览GitHub上提供的源文件:Spring Boot 2.3.x
  • 在IntelliJ Idea中按两次<kbd>Left Shift</kbd>,然后在Classes选项卡中搜索DefaultLogbackConfiguration

我找到这个信息的来源是https://www.logicbig.com/tutorials/spring-framework/spring-boot/logging-console-pattern.html。

英文:

I have just found out this configuration is available at the DefaultLogbackConfiguration file under Spring Boot project:

private static final String CONSOLE_LOG_PATTERN = &quot;%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} &quot;
			+ &quot;%clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} &quot;
			+ &quot;%clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} &quot;
			+ &quot;%clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}&quot;;

To find the pattern for a certain Spring Boot version, either:

  • Browse the source file available at GitHub: Spring Boot 2.3.x.
  • In IntelliJ Idea press 2x <kbd>Left Shift</kbd> and search in the Classes tab for DefaultLogbackConfiguration.

The source of my finding is https://www.logicbig.com/tutorials/spring-framework/spring-boot/logging-console-pattern.html.

答案2

得分: 10

如果您正在使用logback-spring.xml,那么将以下内容添加到您的XML文件中将自动使用Spring的默认logback配置来配置控制台输出。

<!-- language: lang-html -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
    <appender-ref ref="CONSOLE" />
</root>

参考链接:https://docs.spring.io/spring-boot/docs/2.2.6.RELEASE/reference/html/howto.html#howto-configure-logback-for-logging

英文:

If you are using logback-spring.xml, then adding the following to your xml would automatically pick up spring's default logback configuration for console appender.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;include resource=&quot;org/springframework/boot/logging/logback/defaults.xml&quot;/&gt;
&lt;include resource=&quot;org/springframework/boot/logging/logback/console-appender.xml&quot; /&gt;
&lt;root level=&quot;INFO&quot;&gt;
    &lt;appender-ref ref=&quot;CONSOLE&quot; /&gt;
&lt;/root&gt;

<!-- end snippet -->

Reference: https://docs.spring.io/spring-boot/docs/2.2.6.RELEASE/reference/html/howto.html#howto-configure-logback-for-logging

huangapple
  • 本文由 发表于 2020年8月5日 00:25:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63251142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定