在我的 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