27

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?

2 Answers 2

42

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 Left Shift and search in the Classes tab for DefaultLogbackConfiguration.

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


Edit: The default Logback console logger configuration (for example setting the logger to the DEBUG level) can be overridden as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
    <root level="DEBUG">
        <appender-ref ref="CONSOLE" />
    </root>
</configuration>
Sign up to request clarification or add additional context in comments.

1 Comment

Here's the full string without being split up: %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}
16

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.

<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>

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.