0

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 Answers1

0

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.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Yes, I understand, but with v2.7.1 Spring Boot it worked. And in the documentation I found this %C{1.} format as well (https://logging.apache.org/log4j/2.x/manual/layouts.html#patterns). That's why I just don't understand why it does not work with v3.0. – Bernadett Kovács-Szenti Aug 01 '23 at 06:14
  • And I would like to use %C{1.} pattern (org.apache.commons.Foo ==> o.a.c.Foo) instead of %C{1} pattern (org.apache.commons.Foo ==> Foo). – Bernadett Kovács-Szenti Aug 01 '23 at 06:21
  • That link is for Apache log4j2 logging library. Your application is using the logback logging library. Probably your Spring boot 2.7.1 used log4j2 but your current application does not. Use the correct documentation or investigate how to change logging libraries. – aled Aug 01 '23 at 10:13
  • Ah, okay, thank you very much, I will check the dependencies. – Bernadett Kovács-Szenti Aug 02 '23 at 11:39