如何为特定的grok模式编写logback XML

时间:2018-11-05 16:22:53

标签: xml spring logback

我的任务是满足以下grok模式:

%{TIMESTAMP_ISO8601:log_time}\s\[%{HOSTNAME:hostname}\]\[%{DATA:jvm.name}\]\[%{WORD:loglevel}\]\[%{DATA: app.name}\]\[(%{DATA:user.name})?\](\[Request-Id:%{DATA:Request-Id}\])?%{GREEDYDATA:message}

由于反斜杠和'{'-s,所以我不能这样做。

我在以下logback.xml中对其进行了修改:

<configuration> <appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>
            %TIMESTAMP_ISO8601:log_time [%HOSTNAME:hostname] [%DATA:jvm.name] [%WORD:loglevel][%DATA: app.name][(%DATA:user.name)?]([Request-Id:%DATA:Request-Id])?%GREEDYDATA:message
        </Pattern>
    </layout>
</appender>

<logger name="com.mkyong.web" level="info"
    additivity="false">
    <appender-ref ref="SYSLOG" />
</logger>

<root level="info">
    <appender-ref ref="SYSLOG" />
</root>

现在我有以下例外情况:

18:13:43,689 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - There is no conversion class registered for conversion word [TIMESTAMP_ISO8601]18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - [TIMESTAMP_ISO8601] is not a valid conversion word
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - There is no conversion class registered for conversion word [HOSTNAME]
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - [HOSTNAME] is not a valid conversion word
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - There is no conversion class registered for conversion word [DATA]
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - [DATA] is not a valid conversion word
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - There is no conversion class registered for conversion word [WORD]
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - [WORD] is not a valid conversion word
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - There is no conversion class registered for conversion word [DATA]
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - [DATA] is not a valid conversion word
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - There is no conversion class registered for conversion word [DATA]
    18:13:43,690 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@6dde5c8c - [DATA] is not a valid conversion word

可能是问题所在,我尝试了几乎所有组合,但我不满意这种模式。

我在Spring Boot 2.0.5中使用它

0 个答案:

没有答案