springboot logback: java.lang.ClassNotFoundException: org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout

huangapple go评论132阅读模式
英文:

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:

    &lt;appender name=&quot;FILE_ERROR&quot; class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;
        &lt;file&gt;${LOG_PATH}/${appName}/${appName}-error.log&lt;/file&gt;
        &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.TimeBasedRollingPolicy&quot;&gt;
            &lt;fileNamePattern&gt;${LOG_PATH}/${appName}/${appName}-error-%d{yyyy-MM-dd}.%i.log&lt;/fileNamePattern&gt;
            &lt;timeBasedFileNamingAndTriggeringPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP&quot;&gt;
                &lt;maxFileSize&gt;200MB&lt;/maxFileSize&gt;
            &lt;/timeBasedFileNamingAndTriggeringPolicy&gt;
        &lt;/rollingPolicy&gt;
        &lt;append&gt;true&lt;/append&gt;
        &lt;encoder class=&quot;ch.qos.logback.core.encoder.LayoutWrappingEncoder&quot;&gt;
            &lt;layout class=&quot;org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout&quot;&gt;
                &lt;pattern&gt;${CONSOLE_LOG_PATTERN}&lt;/pattern&gt;
            &lt;/layout&gt;
        &lt;/encoder&gt;
        &lt;filter class=&quot;ch.qos.logback.classic.filter.LevelFilter&quot;&gt;
            &lt;level&gt;error&lt;/level&gt;
            &lt;onMatch&gt;ACCEPT&lt;/onMatch&gt;
            &lt;onMismatch&gt;DENY&lt;/onMismatch&gt;
        &lt;/filter&gt;
    &lt;/appender&gt;

but when I start my application, logback shows the following error:

Exception in thread &quot;main&quot; 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 :

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.skywalking&lt;/groupId&gt;
    &lt;artifactId&gt;apm-toolkit-logback-1.x&lt;/artifactId&gt;
    &lt;version&gt;8.1.0&lt;/version&gt;
&lt;/dependency&gt;

gradle

compile group: &#39;org.apache.skywalking&#39;, name: &#39;apm-toolkit-logback-1.x&#39;, version: &#39;8.1.0&#39;

huangapple
  • 本文由 发表于 2020年10月1日 02:20:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/64143573.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定