Skip to content

Commit 63f984e

Browse files
committed
add another check before we execute the synchronized code to propagate
1 parent d81e229 commit 63f984e

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
@@ -175,15 +175,19 @@ public void publish(LogRecord record) {
175175
return;
176176
}
177177

178+
// Only execute synchronized code if we really have to
178179
if (this.installAsLevelPropagator) {
179180
synchronized(this) {
180-
@SuppressWarnings("resource") // no need to close the AutoCloseable ctx here
181-
LoggerContext context = LoggerContext.getContext(false);
182-
context.addPropertyChangeListener(this);
183-
propagateLogLevels(context.getConfiguration());
184-
// note: java.util.logging.LogManager.addPropertyChangeListener() could also
185-
// be set here, but a call of JUL.readConfiguration() will be done on purpose
186-
this.installAsLevelPropagator = false;
181+
// Check again to make sure we still have to propagate the levels at this point
182+
if (this.installAsLevelPropagator) {
183+
@SuppressWarnings("resource") // no need to close the AutoCloseable ctx here
184+
LoggerContext context = LoggerContext.getContext(false);
185+
context.addPropertyChangeListener(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;
190+
}
187191
}
188192
}
189193

0 commit comments

Comments
 (0)