1

我正在尝试LogstashTcpSocketAppender通过logback-spring.xml. 当我将这些行添加 <stackTrace>LogstashEncoder我得到一个错误 Error is: "weblogic.application.ModuleException: java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter@51:25 - no applicable action for [stackTrace], current ElementPath is [[configuration][appender][encoder][stackTrace]]。如果我删除<stackTrace><fieldName>stackTrace</fieldName>并只保留<throwableConverter>它可以正常工作。任何帮助都深表感谢。

logback-spring.xml

<appender name="LOGSTASH"
              class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>${LOGSTASH_HOST}:${LOGSTASH_PORT}</destination>
        <encoder charset="UTF-8"
                 class="net.logstash.logback.encoder.LogstashEncoder">
            <stackTrace>
                <fieldName>stackTrace</fieldName>
                <throwableConverter
                        class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                    <rootCauseFirst>true</rootCauseFirst>
                </throwableConverter>
            </stackTrace>
        </encoder>
    </appender>

    <appender name="ASYNC_LOGSTASH"
              class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="LOGSTASH"/>
    </appender>

错误日志:

Caused By: java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@51:25 - no applicable action for [stackTrace], current ElementPath  is [[configuration][appender][encoder][stackTrace]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@52:28 - no applicable action for [fieldName], current ElementPath  is [[configuration][appender][encoder][stackTrace][fieldName]]
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:166)
        at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:82)
        at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:264)
        Truncated. see log file for complete stacktrace
4

1 回答 1

2

我相信<stackTrace>需要<providers>在编码器中的一个元素中。

尝试

<appender name="LOGSTASH"
          class="net.logstash.logback.appender.LogstashTcpSocketAppender">
    <destination>${LOGSTASH_HOST}:${LOGSTASH_PORT}</destination>
    <encoder charset="UTF-8"
             class="net.logstash.logback.encoder.LogstashEncoder">
       <providers>
        <stackTrace>
            <fieldName>stackTrace</fieldName>
            <throwableConverter
                    class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                <rootCauseFirst>true</rootCauseFirst>
            </throwableConverter>
        </stackTrace>
       </providers>
    </encoder>
</appender>

<appender name="ASYNC_LOGSTASH"
          class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="LOGSTASH"/>
</appender>

更多细节在这里: https ://github.com/logstash/logstash-logback-encoder#tcp-appenders

或者直接使用如下:

<encoder class="net.logstash.logback.encoder.LogstashEncoder">
  <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
    <maxDepthPerThrowable>30</maxDepthPerThrowable>
    <maxLength>2048</maxLength>
    <shortenedClassNameLength>20</shortenedClassNameLength>
    <exclude>sun\.reflect\..*\.invoke.*</exclude>
    <exclude>net\.sf\.cglib\.proxy\.MethodProxy\.invoke</exclude>
    <evaluator class="myorg.MyCustomEvaluator"/>
    <rootCauseFirst>true</rootCauseFirst>
    <inlineHash>true</inlineHash>
  </throwableConverter>
</encoder>
于 2020-05-13T13:29:12.880 回答