I'm using Logback and Logstash in a SpringBoot application.
In the logback.xml I have a property with the name of the service, and is like:
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<property name="spring.application.name" calue="service"/>
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>localhost:9600</destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="stash" />
</root>
</configuration>
The Logstash conf file is like:
input{ tcp{
port=> 9600
host=>logstash
}
}
filter {
grok {
match => {
"message" =>
"^%{TIMESTAMP_ISO8601:timestamp}\s+%{LOGLEVEL:level}\s+%{NUMBER:pid}\s+---\s+\[\s*%{USERNAME:thread}\s*\]\s+%{JAVAFILE:class}\s*:\s*%{DATA:themessage}(?:\n+(?<stacktrace>(?:.|\r|\n)+))?$"
}
}
date {
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss.SSS" ]
}
mutate {
remove_field => ["@version"]
add_field => {
"appid" => "%{[path]}"
}
add_field => {
"levell" => "level"
}
add_field => {
"mensage" => "message"
}
}
}
output{
elasticsearch {
hosts => ["elasticsearch"]
index => "indice"
}
stdout{}
}
How can I do to add the property of application name from the logback file as a field?
From the logstash-logback-encoder docs:
By default your logback properties are local scope and aren't included. Try setting them to
scope="context"
.