Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 863
Nikolas Charalambidis Avatar asked Aug 04 '20 16:08

Nikolas Charalambidis


People also ask

Which is the default logging file in spring boot spring log?

By default, Spring Boot will only log to the console and will not write log files. If you want to write log files in addition to the console output you need to set a logging. file or logging. path property (for example in your application.

What is the spring boot default logging pattern?

The default logging configuration in Spring Boot is a Logback implementation at the info level for logging the output to console. The first info log is printed, followed by a seven-line banner of Spring and then the next info log. The debug statement is suppressed.

Where can I find logs in spring boot application?

By default Spring Boot does not output logs to any file. If you want to have logs written in a file (in addition to the console output) then you should use either of logging. file or logging. path properties (not both).

Where does Logback xml go in spring boot?

In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.


2 Answers

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

like image 119
Arvinth Shriram Avatar answered Sep 27 '22 19:09

Arvinth Shriram


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 fulltext search for DefaultLogbackConfiguration

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

like image 45
Nikolas Charalambidis Avatar answered Sep 27 '22 19:09

Nikolas Charalambidis