[Solved] logback log format adjustment error: Failed to create converter for [%M] keyword

Adjust the log format of logback, and the program starts to report an error.

before fixing:

    <property name=”logLayout” value=”%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{10} :%-3L – %msg %X{span} %n”/>

adjusted:

   <property name=”logLayout” value=”%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger.%M\(%L\) – %msg %n” />

Error after adjustment:

Failed to create converter for [%M] keyword

 

The content of the logback-spring.xml file after format adjustment, before the format adjustment, the program is normal, and an error is reported after the adjustment.

<?xml version="1.0" encoding="UTF-8"? >
<configuration
 
    <contextName>emc-service</contextName>
 
    <springProperty scope="context" name="logging.path" source="logging.path"
                    defaultValue="/data/logs/emc-service"/>
    <springProperty scope="context" name="logging.level.root" source="logging.level.root"
                    defaultValue="info"/>
 
    <property name="logLayout" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %-logger.%M\(%L\) - %msg %n"/>
    <! --%d date | %color() text color | -5level log level | %logger{10} is the class path | %-3L lines | %msg log content | %ex is the exception in log.error(xx,exption) | -->
    <! --><property name="logLayout" value="%blue(%-4relative) %d{yyyy-MM-dd HH:mm:ss.SSS} | [%thread] | %highlight(%-5level) | %logger{10} :%-3L - % yellow(%msg) %X{span}%n"/> -->
 
    <! -- Logger, date scrolling logging -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <! -- Path and filename of the log file being logged -->
        <file>${logging.path}/emc-service.log</file
        <! -- Rolling policy for logger, by date, by size -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <! -- The path to the archived log file, e.g. today is the 2013-12-21 log, the path to the currently written log file is specified by the file node, you can set this file to a different path than the file specified by file, thus placing the current log file or the archived log file in a different directory.
            And the log file of 2013-12-21 in specified by fileNamePattern. %d{yyyy-MM-dd} specifies the date format and %i specifies the index -->
            <fileNamePattern>${logging.path}/%d{yyyy-MM,aux}/emc-service.%d.%i.gz</fileNamePattern>
            <! -- In addition to logging by log, it is also configured that the log file cannot exceed 2M, and if it exceeds 2M, the log file will start with index 0.
            Name the log file, e.g. log-error-2013-12-21.0.log -->
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>300MB</maxFileSize
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory
        </rollingPolicy>
        <! -- Append method of logging -->
        <append>true</append>
        <! -- Format of log file -->
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logLayout}</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender>
 
    <! -- Logger, date scrolling logging -->
    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <! -- Path and filename of the log file being logged -->
        <file>${logging.path}/emc-service-error.log</file
 
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch
            <onMismatch>DENY</onMismatch>
        </filter>
 
        <! -- Logger's rolling policy, by date, by size -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <! -- The path to the archived log file, e.g. today is the 2013-12-21 log, the path to the currently written log file is specified by the file node, you can set this file to a different path than the file specified by file, thus placing the current log file or the archived log file in a different directory.
            And the log file of 2013-12-21 in specified by fileNamePattern. %d{yyyy-MM-dd} specifies the date format and %i specifies the index -->
            <fileNamePattern>${logging.path} /%d{yyyy-MM,aux}/emc-service-error.%d.%i.gz
            </fileNamePattern>
            <! -- In addition to logging by log, it is also configured that the log file cannot exceed 2M, and if it exceeds 2M, the log file will start with index 0.
            Name the log file, e.g. log-error-2013-12-21.0.log -->
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory
        </rollingPolicy>
        <! -- Append method of logging -->
        <append>true</append>
        <! -- Format of log file -->
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logLayout}</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender
 
    <appender name="STDOUT" class="ch.qos.logback.core.
        <! --encoder is configured as PatternLayoutEncoder by default -->
        <encoder
            <pattern>${logLayout}</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender>
 
    <root level="${logging.level.root}">
        <! -- weighted logging -->
        <appender-ref ref="FILE"/>
        <! -- Error log -->
        <appender-ref ref="ERROR"/>
    </root
 
    <springProfile name="dev">
        <root level="${logging.level.root}">
            <appender-ref ref="STDOUT"/>
        </root
    </springProfile>
</configuration>

 

Solution:

Replace all placeholders ${logLayout} with log format content without placeholders

${logLayout} is replaced by %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger.%M\(%L\) – %msg %n

 

Error Messages:

2022-06-07 10:34:17.943 [main] ERROR org.springframework.boot.SpringApplication.%PARSER_ERROR[M] - Application startup failed 
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.pattern.parser.Compiler@66048ac4 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.MethodOfCallerConverter] as a composite converter for keyword [M] ch.qos.logback.core.util.IncompatibleClassException
ERROR in ch.qos.logback.core.pattern.parser.Compiler@66048ac4 - Failed to create converter for [%M] keyword
ERROR in ch.qos.logback.core.pattern.parser.Compiler@4f525e13 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.MethodOfCallerConverter] as a composite converter for keyword [M] ch.qos.logback.core.util.IncompatibleClassException
ERROR in ch.qos.logback.core.pattern.parser.Compiler@4f525e13 - Failed to create converter for [%M] keyword
ERROR in ch.qos.logback.core.pattern.parser.Compiler@5d404a3c - Failed to instantiate converter class [ch.qos.logback.classic.pattern.MethodOfCallerConverter] as a composite converter for keyword [M] ch.qos.logback.core.util.IncompatibleClassException
ERROR in ch.qos.logback.core.pattern.parser.Compiler@5d404a3c - Failed to create converter for [%M] keyword
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
        at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:81)
        at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:59)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114)
        at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:304)
        at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:277)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
        at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
        at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:145)
        at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:64)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:341)
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1445)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1409)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:822)
        at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:275)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:524)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:46)
        at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188)
        at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:513)
        at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:154)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:173)
        at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:447)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:66)
        at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:784)
        at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:753)
        at org.eclipse.jetty.util.Scanner.scan(Scanner.java:641)
        at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:540)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:146)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:599)
        at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:249)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
        at org.eclipse.jetty.server.Server.start(Server.java:407)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:100)
        at org.eclipse.jetty.server.Server.doStart(Server.java:371)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.xml.XmlConfiguration.lambda$main$0(XmlConfiguration.java:1888)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1837)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:218)
        at org.eclipse.jetty.start.Main.start(Main.java:491)
        at org.eclipse.jetty.start.Main.main(Main.java:77)

 

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *