簡體   English   中英

用於 Spring 引導日志記錄的默認 CONSOLE_LOG_PATTERN 是什么以及在哪里可以找到它?

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

Spring 引導參考文檔4.6。 自定義日志配置狀態有關默認系統屬性的狀態,這些屬性表示要在控制台上使用的默認日志記錄模式(僅支持默認的 Logback 設置)。

  • Spring 環境: logging.pattern.console
  • 系統屬性: CONSOLE_LOG_PATTERN

我想所有 Spring 引導框架用戶都熟悉默認的日志行:

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

只要我想看看它的外觀並獲得靈感來定義我自己的,我在哪里可以找到當前使用的 Spring Boot 版本的默認值?

我剛剛發現此配置可在 Spring 引導項目下的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 引導版本的模式,請執行以下任一操作:

  • 瀏覽 GitHub 提供的源文件: Spring Boot 2.3.x
  • 在 IntelliJ Idea 中按 2x Left Shift並全文搜索DefaultLogbackConfiguration

我發現的來源是https://www.logicbig.com/tutorials/spring-framework/spring-boot/logging-console-pattern.html

如果您使用的是logback-spring.xml ,那么將以下內容添加到您的 xml 將自動為控制台附加程序選擇 spring 的默認 logback 配置。

 <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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM