我的 Spring Boot 日志目前如下所示。
{"@timestamp":"2018-08-07T14:49:21.244+01:00","@version":"1","message":"Starting Application on ipkiss bla bla)","logger_name":"logger name....","thread_name":"main","level":"INFO","level_value":20000}
使用如下的 logback-spring.xml 设置
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="com.ipkiss.correlate.logback.CorrelationPatternLayoutEncoder">
<pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} id = %id %m%n%wEx</pattern>
</encoder>
</appender>
我的 LayoutEncoder 类看起来像这样
public class CorrelationPatternLayoutEncoder extends PatternLayoutEncoder {
public CorrelationPatternLayoutEncoder() {
}
@Override
public void start() {
PatternLayout patternLayout = new PatternLayout();
patternLayout.getDefaultConverterMap().put("id", CorrelationConverter.class.getName());
patternLayout.setContext(context);
patternLayout.setPattern(getPattern());
patternLayout.setOutputPatternAsHeader(outputPatternAsHeader);
patternLayout.start();
this.layout = patternLayout;
this.started = true;
}
}
我想要实现的是将 id 添加到日志中,我无法让 logstach 附加我的 id,我根据文档尝试了自定义字段,但我无法使其工作,有什么想法可以实现吗?
这就是我想要结束的
{"id":"3a7ccd34-d66a-4fcc-a12e-763a395a496c","@timestamp":"2018-08-07T14:49:21.244+01:00","@version":"1","message":"Starting Application on ipkiss bla bla)","logger_name":"logger name....","thread_name":"main","level":"INFO","level_value":20000}
或在日志末尾附加 id。