diff options
author | Luca Milanesio <luca.milanesio@gmail.com> | 2015-03-09 11:00:54 +0000 |
---|---|---|
committer | Luca Milanesio <luca.milanesio@gmail.com> | 2015-03-09 11:08:20 +0000 |
commit | ae055c09e13b95278a795b4f5eb45dbe8b99a140 (patch) | |
tree | fd43bbd903ef126bca19f14fdd5b94db3ddabd74 | |
parent | 50e3b57294f445a51252c6d858aaf402ea3a24c7 (diff) |
Fix replication_log with external log4j.configurationv2.10.2
When using an external log4j configuration using the JVM container
option -Dlog4j.configuration=file:///... the replication log appender
wasn’t configured at all.
This was mainly due to the fact that all appenders were closed and
removed before invoking the SystemLog.createAsyncAppender() that was
then unable to find any appender to attach.
Flipping the operations and using the single removeAppender instead
of the removeAllAppenders (the name is a lie: it does not only remove
but also *CLOSE* all the appenders, making them unusable) everything
is OK with an external configuration.
Issue: 3230
Change-Id: I4d9b153d49731a0a7d5c5df863c69dd2165cc883
-rw-r--r-- | src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java index 1079981..50f1b8b 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationLogFile.java @@ -19,6 +19,7 @@ import com.google.gerrit.extensions.systemstatus.ServerInformation; import com.google.gerrit.server.util.SystemLog; import com.google.inject.Inject; +import org.apache.log4j.AsyncAppender; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; @@ -41,10 +42,12 @@ public class ReplicationLogFile implements LifecycleListener { if (!started) { Logger replicationLogger = LogManager.getLogger(ReplicationQueue.REPLICATION_LOG_NAME); - replicationLogger.removeAllAppenders(); - replicationLogger.addAppender(systemLog.createAsyncAppender( - replicationLogger.getName(), new PatternLayout("[%d] [%X{" - + PushOne.ID_MDC_KEY + "}] %m%n"))); + String loggerName = replicationLogger.getName(); + AsyncAppender asyncAppender = systemLog.createAsyncAppender( + loggerName, new PatternLayout("[%d] [%X{" + + PushOne.ID_MDC_KEY + "}] %m%n")); + replicationLogger.removeAppender(loggerName); + replicationLogger.addAppender(asyncAppender); replicationLogger.setAdditivity(false); started = true; } |