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 <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-05-22 11:01:21 +02:00
parent dc2c7991a2
commit c183569ad5
3 changed files with 13 additions and 10 deletions

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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()));
}