Skip to content

Commit

Permalink
Log MDC by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Jun 20, 2024
1 parent 087ddea commit bc46720
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static final class Builder implements org.apache.logging.log4j.core.util.Builder
private String serviceEnvironment;

@PluginBuilderAttribute
private boolean logMdc = true;
private boolean logMdc;

@Override
public StructuredLoggingLayout build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private StructuredLoggingEncoder createStructuredLoggingEncoder(LogbackConfigura
encoder.setFormat(format);
encoder.setCharset(charset);
encoder.setPid(resolveLong(config, "${PID:--1}"));
encoder.setLogMdc(true);
String applicationName = resolve(config, "${APPLICATION_NAME:-}");
if (StringUtils.hasLength(applicationName)) {
encoder.setServiceName(applicationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<Console name="Console" target="SYSTEM_OUT" follow="true">
<Select>
<StructuredLoggingEnabledArbiter appender="console">
<StructuredLoggingLayout format="${sys:CONSOLE_LOG_STRUCTURED}" charset="${sys:CONSOLE_LOG_CHARSET}"/>
<StructuredLoggingLayout format="${sys:CONSOLE_LOG_STRUCTURED}" charset="${sys:CONSOLE_LOG_CHARSET}" logMdc="true"/>
</StructuredLoggingEnabledArbiter>
<DefaultArbiter>
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" charset="${sys:CONSOLE_LOG_CHARSET}" />
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" charset="${sys:CONSOLE_LOG_CHARSET}"/>
</DefaultArbiter>
</Select>
<Filters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Console name="Console" target="SYSTEM_OUT" follow="true">
<Select>
<StructuredLoggingEnabledArbiter appender="console">
<StructuredLoggingLayout format="${sys:CONSOLE_LOG_STRUCTURED}" charset="${sys:CONSOLE_LOG_CHARSET}"/>
<StructuredLoggingLayout format="${sys:CONSOLE_LOG_STRUCTURED}" charset="${sys:CONSOLE_LOG_CHARSET}" logMdc="true"/>
</StructuredLoggingEnabledArbiter>
<DefaultArbiter>
<PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" charset="${sys:CONSOLE_LOG_CHARSET}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ sample.name=Andy
# TODO MH: Remove
#logging.structured.file=logfmt
#logging.file.name=/home/mhalbritter/tmp/log.txt
#logging.structured.console=custom
logging.structured.console=logfmt
#logging.structured.console=smoketest.simple.CustomFormat

0 comments on commit bc46720

Please sign in to comment.