8

求助…logback 输出 json 日志配置 appender 配置懵逼了…请大家帮助,谢谢…

 2 years ago
source link: https://www.v2ex.com/t/809864
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

求助…logback 输出 json 日志配置 appender 配置懵逼了…请大家帮助,谢谢…

  heavyrainn · 1 天前 · 309 次点击

我想配置的是使用 CompositeJsonGeneratorDecorator (因为需要使用 net.logstash.logback.argument.StructuredArguments.kv 给日志追加输出 KV 项),按日输出日志的 appender,logback.xml 的配置如下会报错

<appender name="infoFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <jsonGeneratorDecorator class="net.logstash.logback.decorate.CompositeJsonGeneratorDecorator">
                <decorator class="net.logstash.logback.decorate.PrettyPrintingJsonGeneratorDecorator"/>
            </jsonGeneratorDecorator>
        </encoder>
        <!-- ThresholdFilter:临界值过滤器,过滤掉 TRACE 和 DEBUG 级别的日志 -->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/log.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>30</maxHistory><!--保存最近 30 天的日志-->
        </rollingPolicy>
    </appender>

烦请大家帮看一下,非常感谢~


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK