Logback PatternLayout class name format problem with Spring Boot 3.0

999 Views Asked by At

I would like to ask your help. I have a small Spring Boot Application project with v2.7.1. I started to change the version to v3.0.6 and I faced with a logback problem. In my logback xml file I use %C{1.} for PatternLayout but it does not work, I get an error. When I replace it with %C{1} it's working. I would like to use %C{1.} pattern and I don't know why I cannot.

Thanks your help in advance!

Appender in logback xml:

    <appender name="Console"
              class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
            </Pattern>
        </layout>
    </appender>

Error:

Caused by: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.classic.pattern.LoggerConverter@5b080f3a - failed to parse integer string [1.] java.lang.NumberFormatException: For input string: "1."
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.reportConfigurationErrorsIfNecessary(LogbackLoggingSystem.java:260)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:247)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:187)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)
    ... 19 more

I tried to edit %C{1.} to %C{1} and it worked but this is another pattern for formatting a class name in logs.

1

There are 1 best solutions below

4
On

Don't assume a bug until you discarded user error. %C{1.}: the %C (or %class) conversion word takes an integer as an argument to shorten the class name, but you passed a floating point number because of the decimal dot.

The error is clear in the error message failed to parse integer string [1.] java.lang.NumberFormatException: For input string: "1." and above documentation link provides the definition.

Remove that dot and it should resolve the issue.