如何在Logback LogstashSocketAppender中更改标准字段名称?

时间:2018-09-10 11:52:09

标签: logback logstash-logback-encoder

在我的Spring后端中:标准日志字段名称为:“消息” “级别” ,logback.xml文件非常有用:

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds">
    <property resource="application.properties"/>
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] <%-5level> [Backend] <%thread> &msg%n
            </Pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="stdout"/>
    </root>
</configuration>

问题: 如何使用 LogstashSocketAppender 将标准日志字段名称从“ 消息”更改为“ 日志消息”?

我已经尝试添加此附加程序:

<appender name="stash" class="net.logstash.logback.appender.LogstashSocketAppender">
    <host>localhost</host>
    <port>6002</port>
    <customFields>
        {
        "timestamp":"%d{yyyy-MM-dd HH:mm:ss.SSS}",
        "component": "Backend",
        "log-message": "%msg",
        "log-level": "%-5level"
        }</customFields>
</appender>

但是我的呕吐看起来像这样:

{
"message":"correct log message here"
"log-message":"%msg" <--- BAD VALUE

1 个答案:

答案 0 :(得分:0)

我已经通过使用模式完成了此操作:

function validatemycode() {
    $('datagroup').on('keyup', 'input[id^="datagroup_1"]', function () {
        if (!this.value){
            alert('You must enter two characters.');
        }
    })
}

编辑:当然,您必须在logstash中创建<appender name="stash" class="net.logstash.logback.appender.LogstashSocketAppender"> <host>${logstash.host}</host> <port>${logstash.port}</port> <provider class="net.logstash.logback.composite.loggingevent.LoggingEventPatternJsonProvider"> <pattern> { "log-message": "%msg", "component": "Backend", "timestamp": "%d{yyyy-MM-dd HH:mm:ss.SSS}", "log-level": "%-5level", "thread-id": "%thread" } </pattern> </provider> </appender> 过滤器以侦听此模式。