英文:
springboot logback: java.lang.ClassNotFoundException: org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout
问题
我使用Spring Boot(版本:2.1.5.RELEASE)创建项目,然后使用logback-spring.xml来记录日志。
配置如下:
<appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${appName}/${appName}-error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/${appName}/${appName}-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>200MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<append>true</append>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</layout>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>error</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
但是,当我启动应用程序时,logback显示以下错误:
Exception in thread "main" java.lang.IllegalStateException: 检测到Logback配置错误:
ch.qos.logback.core.joran.action.NestedComplexPropertyIA中的错误 - 无法创建类型为[org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout]的组件[layout],java.lang.ClassNotFoundException:org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout
ch.qos.logback.core.joran.spi.Interpreter@20:26中的错误 - 没有适用于[pattern]的操作,当前ElementPath为[[configuration][appender][encoder][layout][pattern]]
ch.qos.logback.core.joran.action.NestedComplexPropertyIA中的错误 - 无法创建类型为[org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout]的组件[layout],java.lang.ClassNotFoundException:org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout
是否遗漏了一些操作(或如何添加它们)以供logback使用?
英文:
I use springboot (version: 2.1.5.RELEASE) create project, then use logback-spring.xml to record log .
the configration like this:
<appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${appName}/${appName}-error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/${appName}/${appName}-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>200MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<append>true</append>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</layout>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>error</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
but when I start my application, logback shows the following error:
Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [layout] of type [org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout] java.lang.ClassNotFoundException: org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout
ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:26 - no applicable action for [pattern], current ElementPath is [[configuration][appender][encoder][layout][pattern]]
ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [layout] of type [org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout] java.lang.ClassNotFoundException: org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout
Lost some action (or how to add them) for logback?
答案1
得分: 1
使用 TraceIdPatternLogbackLayout
需要在项目中添加对工具包的依赖。
Maven:
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId>
<version>8.1.0</version>
</dependency>
Gradle:
compile group: 'org.apache.skywalking', name: 'apm-toolkit-logback-1.x', version: '8.1.0'
英文:
To use TraceIdPatternLogbackLayout
from apm-toolkit-logback-1.x
you have to dependency the toolkit
maven :
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId>
<version>8.1.0</version>
</dependency>
gradle
compile group: 'org.apache.skywalking', name: 'apm-toolkit-logback-1.x', version: '8.1.0'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论