我的任务是满足以下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中使用它