英文:
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 = "%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}";
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 forDefaultLogbackConfiguration
.
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>
英文:
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 -->
<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>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论