-
According to the document written:
I am using the default LogstashEncoder, and if I want to modify the message column with some mdc value. My logbook configuration will need to change from a simple three line xml <appender name="simple" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender> To something like this? <appender name="customized_one" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<threadName />
<timestamp />
<version />
<loggerName />
<logLevel />
<logLevelValue />
<mdc />
<stackTrace />
<pattern>
<pattern>
{
"message": "%mdc{custom_value} %message"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender> I don't even know if I miss some origin fields or not... Or there is another way to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Using a LogstashEncoder is similar to the following configuration: <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp />
<version />
<message />
<loggerName />
<threadName />
<logLevel />
<logLevelValue />
<callerData />
<stackTrace />
<mdc />
<tags />
<logstashMarkers />
<arguments />
</providers>
</encoder> I recon the documentation is not very clear on the subject and we will do our best to take some time to review it in the near future. Sorry about that. |
Beta Was this translation helpful? Give feedback.
-
To add extra JsonProviders to those already registered by LogstashEncoder, you have to use the <encoder class="net.logstash.logback.encoder.LogstashEncoder">
<!-- Add a new provider after those than come with the LogstashEncoder -->
<provider class="net.logstash.logback.composite.loggingevent.LoggingEventPatternJsonProvider">
<pattern>
{
"message": "%mdc{custom_value} %message"
}
</pattern>
</provider>
<!-- Disable the default message provider -->
<fieldNames>
<message>[ignore]</message>
</fieldNames>
</encoder> You can add several additional JsonProviders using multiple In this example, the pattern provider produces a "message" JSON field that will conflict with the message field already produced by the MessageJsonProvider registered by the LogstashEncoder. Different options to avoid the conflict:
Note: using the |
Beta Was this translation helpful? Give feedback.
To add extra JsonProviders to those already registered by LogstashEncoder, you have to use the
<provider>
keyword as shown below:You can add several additional JsonProviders using multiple
<p…