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

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