Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not-abbreviate the source class name in spring-boot's logger name?

When I run a spring-boot application, it shows the following log:

2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

The logger name is abbreviated for the following:

org.springframework.boot.context.embedded.FilterRegistrationBean

How can I show the full source class name for it?

like image 720
user1040933 Avatar asked Jan 01 '26 07:01

user1040933


1 Answers

By default Spring boot uses Logback logging. You can change the configuration by putting a logback.xml file in your class path. They have a default base.xml which defines the overall configuration and includes their defaults.xml file. Because of where the log pattern is defined you will need to created a file that has a few of the items inside copied. Here is an example of a logback.xml I created:

<configuration>
    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
    <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
    <property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%C){cyan} %clr(:){faint} %m%n%wex"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    </root>
    <logger name="org.springframework.web" level="DEBUG"/>
</configuration>

And here is an example of a log message using this configuration:

2015-06-17 09:02:06.511  INFO 18816 --- [           main] org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)

You can tweak the pattern further if you want. See this page and the PatternLayout section for possible items to include.

You can also use other logging implementations per their logging documentation and then configure those as necessary.

UPDATE: As of Spring Boot version 1.3.0 (not released yet as of this edit) you can use logging.pattern.console and logging.pattern.file properties to set the pattern for the default Logback configurations. See the sample properties file here in their documentation. NOTE: This link could change as it points to the build SNAPSHOT docs.

like image 114
Rob Baily Avatar answered Jan 04 '26 12:01

Rob Baily



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!