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:
@@ -41,9 +41,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
public class GarbageCollection {
|
public class GarbageCollection {
|
||||||
private static final Logger log = LoggerFactory.getLogger(GarbageCollection.class);
|
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 GitRepositoryManager repoManager;
|
||||||
private final GarbageCollectionQueue gcQueue;
|
private final GarbageCollectionQueue gcQueue;
|
||||||
private final GcConfig gcConfig;
|
private final GcConfig gcConfig;
|
||||||
@@ -142,7 +139,7 @@ public class GarbageCollection {
|
|||||||
}
|
}
|
||||||
b.append(s);
|
b.append(s);
|
||||||
}
|
}
|
||||||
gcLog.info(b.toString());
|
log.info(b.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logGcConfiguration(
|
private static void logGcConfiguration(
|
||||||
@@ -182,7 +179,6 @@ public class GarbageCollection {
|
|||||||
print(writer, "failed.\n\n");
|
print(writer, "failed.\n\n");
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
b.append("[").append(projectName.get()).append("]");
|
b.append("[").append(projectName.get()).append("]");
|
||||||
gcLog.error(b.toString(), e);
|
|
||||||
log.error(b.toString(), e);
|
log.error(b.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,8 @@ import org.apache.log4j.PatternLayout;
|
|||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
|
|
||||||
public class GarbageCollectionLogFile implements LifecycleListener {
|
public class GarbageCollectionLogFile implements LifecycleListener {
|
||||||
|
private static final String LOG_NAME = "gc_log";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GarbageCollectionLogFile(SitePaths sitePaths, @GerritServerConfig Config config) {
|
public GarbageCollectionLogFile(SitePaths sitePaths, @GerritServerConfig Config config) {
|
||||||
if (SystemLog.shouldConfigure()) {
|
if (SystemLog.shouldConfigure()) {
|
||||||
@@ -38,15 +40,20 @@ public class GarbageCollectionLogFile implements LifecycleListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
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) {
|
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.removeAllAppenders();
|
||||||
gcLogger.addAppender(
|
gcLogger.addAppender(
|
||||||
SystemLog.createAppender(
|
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);
|
gcLogger.setAdditivity(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
/** Runnable to enable scheduling gc to run periodically */
|
/** Runnable to enable scheduling gc to run periodically */
|
||||||
public class GarbageCollectionRunner implements Runnable {
|
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 {
|
static class Lifecycle implements LifecycleListener {
|
||||||
private final WorkQueue queue;
|
private final WorkQueue queue;
|
||||||
@@ -61,7 +61,7 @@ public class GarbageCollectionRunner implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
gcLog.info("Triggering gc on all repositories");
|
log.info("Triggering gc on all repositories");
|
||||||
garbageCollectionFactory.create().run(Lists.newArrayList(projectCache.all()));
|
garbageCollectionFactory.create().run(Lists.newArrayList(projectCache.all()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user