From c183569ad56538dc019d9bec6b63820438b51aec Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Tue, 22 May 2018 11:01:21 +0200 Subject: [PATCH] Don't use separate logger for GC log file Instead add appenders that write to the GC log file to the loggers of the classes that do the GC. Doing this is needed to migrate to Flogger as Flogger requires logger names to match class names. I verified this manually by adding a GC config to the gerrit.config of my local test sever [1] and then checking that the GC log file is still written. [1] Test GC config: [gc] startTime = Fri 10:30 interval = 1m Change-Id: I6f4e5b5b448abf3c0ebfe3a2b2bf89827ece8c81 Signed-off-by: Edwin Kempin --- .../google/gerrit/server/git/GarbageCollection.java | 6 +----- .../gerrit/server/git/GarbageCollectionLogFile.java | 13 ++++++++++--- .../gerrit/server/git/GarbageCollectionRunner.java | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/java/com/google/gerrit/server/git/GarbageCollection.java b/java/com/google/gerrit/server/git/GarbageCollection.java index 3bf89c7d78..997907e2a1 100644 --- a/java/com/google/gerrit/server/git/GarbageCollection.java +++ b/java/com/google/gerrit/server/git/GarbageCollection.java @@ -41,9 +41,6 @@ import org.slf4j.LoggerFactory; public class GarbageCollection { private static final Logger log = LoggerFactory.getLogger(GarbageCollection.class); - public static final String LOG_NAME = "gc_log"; - private static final Logger gcLog = LoggerFactory.getLogger(LOG_NAME); - private final GitRepositoryManager repoManager; private final GarbageCollectionQueue gcQueue; private final GcConfig gcConfig; @@ -142,7 +139,7 @@ public class GarbageCollection { } b.append(s); } - gcLog.info(b.toString()); + log.info(b.toString()); } private static void logGcConfiguration( @@ -182,7 +179,6 @@ public class GarbageCollection { print(writer, "failed.\n\n"); StringBuilder b = new StringBuilder(); b.append("[").append(projectName.get()).append("]"); - gcLog.error(b.toString(), e); log.error(b.toString(), e); } diff --git a/java/com/google/gerrit/server/git/GarbageCollectionLogFile.java b/java/com/google/gerrit/server/git/GarbageCollectionLogFile.java index e03ef678cc..8796fdf839 100644 --- a/java/com/google/gerrit/server/git/GarbageCollectionLogFile.java +++ b/java/com/google/gerrit/server/git/GarbageCollectionLogFile.java @@ -26,6 +26,8 @@ import org.apache.log4j.PatternLayout; import org.eclipse.jgit.lib.Config; public class GarbageCollectionLogFile implements LifecycleListener { + private static final String LOG_NAME = "gc_log"; + @Inject public GarbageCollectionLogFile(SitePaths sitePaths, @GerritServerConfig Config config) { if (SystemLog.shouldConfigure()) { @@ -38,15 +40,20 @@ public class GarbageCollectionLogFile implements LifecycleListener { @Override public void stop() { - LogManager.getLogger(GarbageCollection.LOG_NAME).removeAllAppenders(); + LogManager.getLogger(GarbageCollection.class).removeAllAppenders(); + LogManager.getLogger(GarbageCollectionRunner.class).removeAllAppenders(); } private static void initLogSystem(Path logdir, boolean rotate) { - Logger gcLogger = LogManager.getLogger(GarbageCollection.LOG_NAME); + initGcLogger(logdir, rotate, LogManager.getLogger(GarbageCollection.class)); + initGcLogger(logdir, rotate, LogManager.getLogger(GarbageCollectionRunner.class)); + } + + private static void initGcLogger(Path logdir, boolean rotate, Logger gcLogger) { gcLogger.removeAllAppenders(); gcLogger.addAppender( SystemLog.createAppender( - logdir, GarbageCollection.LOG_NAME, new PatternLayout("[%d] %-5p %x: %m%n"), rotate)); + logdir, LOG_NAME, new PatternLayout("[%d] %-5p %x: %m%n"), rotate)); gcLogger.setAdditivity(false); } } diff --git a/java/com/google/gerrit/server/git/GarbageCollectionRunner.java b/java/com/google/gerrit/server/git/GarbageCollectionRunner.java index e4316c509b..054e56afd6 100644 --- a/java/com/google/gerrit/server/git/GarbageCollectionRunner.java +++ b/java/com/google/gerrit/server/git/GarbageCollectionRunner.java @@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory; /** Runnable to enable scheduling gc to run periodically */ public class GarbageCollectionRunner implements Runnable { - private static final Logger gcLog = LoggerFactory.getLogger(GarbageCollection.LOG_NAME); + private static final Logger log = LoggerFactory.getLogger(GarbageCollectionRunner.class); static class Lifecycle implements LifecycleListener { private final WorkQueue queue; @@ -61,7 +61,7 @@ public class GarbageCollectionRunner implements Runnable { @Override public void run() { - gcLog.info("Triggering gc on all repositories"); + log.info("Triggering gc on all repositories"); garbageCollectionFactory.create().run(Lists.newArrayList(projectCache.all())); }