logback 日志格式调整报错: Failed to create converter for [%M] keyword
把logback的日志格式调整下,程序启动报错.
调整前:
<property name="logLayout" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{10} :%-3L - %msg %X{span}%n"/>
调整后:
<property name="logLayout" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger.%M\(%L\) - %msg %n"/>
调整后报错:
Failed to create converter for [%M] keyword
logback-spring.xml 格式调整后文件内容,格式调整前,程序正常,调整后报错。
<?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 日期 | %color() 文字颜色 | -5level 日志级别 | %logger{10} 是类路径 | %-3L 行数| %msg 日志内容| %ex 是log.error(xx,exption)中exception| --> <!--<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"/>--> <!-- 日志记录器,日期滚动记录 --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在记录的日志文件的路径及文件名 --> <file>${logging.path}/emc-service.log</file> <!-- 日志记录器的滚动策略,按日期,按大小记录 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 归档的日志文件的路径,例如今天是2013-12-21日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。 而2013-12-21的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${logging.path}/%d{yyyy-MM,aux}/emc-service.%d.%i.gz</fileNamePattern> <!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始, 命名日志文件,例如log-error-2013-12-21.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>300MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <maxHistory>30</maxHistory> </rollingPolicy> <!-- 追加方式记录日志 --> <append>true</append> <!-- 日志文件的格式 --> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>${logLayout}</pattern> <charset>utf-8</charset> </encoder> </appender> <!-- 日志记录器,日期滚动记录 --> <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在记录的日志文件的路径及文件名 --> <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> <!-- 日志记录器的滚动策略,按日期,按大小记录 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 归档的日志文件的路径,例如今天是2013-12-21日志,当前写的日志文件路径为file节点指定,可以将此文件与file指定文件路径设置为不同路径,从而将当前日志文件或归档日志文件置不同的目录。 而2013-12-21的日志文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${logging.path} /%d{yyyy-MM,aux}/emc-service-error.%d.%i.gz </fileNamePattern> <!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始, 命名日志文件,例如log-error-2013-12-21.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>100MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <maxHistory>30</maxHistory> </rollingPolicy> <!-- 追加方式记录日志 --> <append>true</append> <!-- 日志文件的格式 --> <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.ConsoleAppender"> <!--encoder 默认配置为PatternLayoutEncoder--> <encoder> <pattern>${logLayout}</pattern> <charset>utf-8</charset> </encoder> </appender> <root level="${logging.level.root}"> <!-- 权量日志 --> <appender-ref ref="FILE"/> <!-- 错误日志 --> <appender-ref ref="ERROR"/> </root> <springProfile name="dev"> <root level="${logging.level.root}"> <appender-ref ref="STDOUT"/> </root> </springProfile> </configuration>
解决方式:
把占位符 ${logLayout} 全部换成 日志格式内容,不使用占位符
${logLayout} 替换成 %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger.%M\(%L\) - %msg %n
报错日志明细:
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)