Logback扩展的ClassicConverter类返回%PARSER_ERROR [NameConvertor]

时间:2018-03-12 17:20:47

标签: java logback

我尝试制作简单的扩展ClassicConverter,如下所示:

package com.test;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

public class NameConverter extends ClassicConverter {
    @Override
    public String convert(ILoggingEvent event) {

        return "This is NameConverter";
    }
}

和logback文件:

<included>

     <conversionRule conversionWord="NameConvertor"
                    converterClass="com.test.PackageNameConverter" />

    <property name="cPattern"
                      value="%d{HH:mm:ss}  [%thread] %logger{35}  |%NameConverter %msg%n" />

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">

        <encoder>
            <pattern>${cPattern}</pattern>
        </encoder>

    </appender>
</included>

但我一直在接受:

19:08:01  [Thread-12] DEBUG  |%PARSER_ERROR[NameConvertor]|  testtest

1 个答案:

答案 0 :(得分:0)

尝试更改为

<conversionRule conversionWord="NameConvertor"
                    converterClass="com.test.PackageNameConverter" />
to 
   <conversionRule conversionWord="NameConvertor"
                    converterClass="com.test.NameConverter" />