Skip to content

Commit a55d28d

Browse files
mknetppkarwasz
authored andcommitted
add another check before we execute the synchronized code to propagate
1 parent e3501e0 commit a55d28d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

log4j-jul/src/main/java/org/apache/logging/log4j/jul/Log4jBridgeHandler.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,19 @@ public void publish(final LogRecord record) {
178178
return;
179179
}
180180

181+
// Only execute synchronized code if we really have to
181182
if (this.installAsLevelPropagator) {
182183
synchronized (this) {
183-
@SuppressWarnings("resource") // no need to close the AutoCloseable ctx here
184-
LoggerContext context = LoggerContext.getContext(false);
185-
context.addConfigurationStartedListener(this);
186-
propagateLogLevels(context.getConfiguration());
187-
// note: java.util.logging.LogManager.addPropertyChangeListener() could also
188-
// be set here, but a call of JUL.readConfiguration() will be done on purpose
189-
this.installAsLevelPropagator = false;
184+
// Check again to make sure we still have to propagate the levels at this point
185+
if (this.installAsLevelPropagator) {
186+
@SuppressWarnings("resource") // no need to close the AutoCloseable ctx here
187+
LoggerContext context = LoggerContext.getContext(false);
188+
context.addConfigurationStartedListener(this);
189+
propagateLogLevels(context.getConfiguration());
190+
// note: java.util.logging.LogManager.addPropertyChangeListener() could also
191+
// be set here, but a call of JUL.readConfiguration() will be done on purpose
192+
this.installAsLevelPropagator = false;
193+
}
190194
}
191195
}
192196

0 commit comments

Comments
 (0)