如何为自定义日志格式化程序配置logback.xml

时间:2014-07-21 17:17:14

标签: log4j logback formatter

import org.apache.log4j.PatternLayout;
import org.apache.log4j.spi.LoggingEvent;

public class Syslog4jPatternlayout extends PatternLayout {

    public String format(LoggingEvent event) {
        return "";
    } 
}

如何配置logback.xml文件以使用此格式化程序?

1 个答案:

答案 0 :(得分:1)

我认为您应该使用logback LayoutBase

public class Syslog4jPatternlayout extends LayoutBase<ILoggingEvent> {

  public String doLayout(ILoggingEvent event) {
      return "";
  }

}

在logback.xml中

<appender name="appender1" class="your appender">
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="com.kp.Syslog4jPatternlayout" />
    </encoder>
  </appender>