Allow to disable log file rotation
On sites where log file rotation is done by an external service such as logrotate [1], administrators may wish to disable Gerrit's default log rotation. Add a new setting, log.rotate, which disables log rotation when set to false. The default is true, for backwards compatibility with current behaviour. [1] http://manpages.ubuntu.com/manpages/zesty/man8/logrotate.8.html Change-Id: I76ebf086929fae7dd528e48385265722332dec0a
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.util.SystemLog;
|
||||
import com.google.inject.Inject;
|
||||
@@ -22,13 +23,13 @@ import java.nio.file.Path;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class GarbageCollectionLogFile implements LifecycleListener {
|
||||
|
||||
@Inject
|
||||
public GarbageCollectionLogFile(SitePaths sitePaths) {
|
||||
public GarbageCollectionLogFile(SitePaths sitePaths, @GerritServerConfig Config config) {
|
||||
if (SystemLog.shouldConfigure()) {
|
||||
initLogSystem(sitePaths.logs_dir);
|
||||
initLogSystem(sitePaths.logs_dir, config.getBoolean("log", "rotate", true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +41,12 @@ public class GarbageCollectionLogFile implements LifecycleListener {
|
||||
LogManager.getLogger(GarbageCollection.LOG_NAME).removeAllAppenders();
|
||||
}
|
||||
|
||||
private static void initLogSystem(Path logdir) {
|
||||
private static void initLogSystem(Path logdir, boolean rotate) {
|
||||
Logger gcLogger = LogManager.getLogger(GarbageCollection.LOG_NAME);
|
||||
gcLogger.removeAllAppenders();
|
||||
gcLogger.addAppender(
|
||||
SystemLog.createAppender(
|
||||
logdir, GarbageCollection.LOG_NAME, new PatternLayout("[%d] %-5p %x: %m%n")));
|
||||
logdir, GarbageCollection.LOG_NAME, new PatternLayout("[%d] %-5p %x: %m%n"), rotate));
|
||||
gcLogger.setAdditivity(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user