Merge "Support for error_log in .json format."
This commit is contained in:
commit
be2b576c1c
|
@ -2654,6 +2654,22 @@ are specified in the link:#container[container section]:
|
|||
javaOptions = -Dcom.sun.jndi.ldap.connect.pool.timeout=300000
|
||||
----
|
||||
|
||||
[[log]]
|
||||
=== Section log
|
||||
|
||||
[[log.jsonLogging]]log.jsonLogging::
|
||||
+
|
||||
If set to true, enables error logging in JSON format (file name: "logs/error_log.json").
|
||||
+
|
||||
Defaults to false.
|
||||
|
||||
[[log.textLogging]]log.textLogging::
|
||||
+
|
||||
If set to true, enables error logging in regular plain text format. Can only be disabled
|
||||
if `jsonLogging` is enabled.
|
||||
+
|
||||
Defaults to true.
|
||||
|
||||
[[mimetype]]
|
||||
=== Section mimetype
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ DEPS = [
|
|||
'//lib/guice:guice-servlet',
|
||||
'//lib/jgit:jgit',
|
||||
'//lib/log:api',
|
||||
'//lib/log:log4j',
|
||||
'//lib/log:jsonevent-layout',
|
||||
'//lib/log:log4j'
|
||||
]
|
||||
|
||||
java_library(
|
||||
|
|
|
@ -197,10 +197,6 @@ public class Daemon extends SiteProgram {
|
|||
throw die("No services enabled, nothing to do");
|
||||
}
|
||||
|
||||
if (!consoleLog) {
|
||||
manager.add(ErrorLogFile.start(getSitePath()));
|
||||
}
|
||||
|
||||
try {
|
||||
start();
|
||||
RuntimeShutdown.add(new Runnable() {
|
||||
|
@ -273,7 +269,7 @@ public class Daemon extends SiteProgram {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void start() {
|
||||
public void start() throws IOException {
|
||||
if (dbInjector == null) {
|
||||
dbInjector = createDbInjector(MULTI_USER);
|
||||
}
|
||||
|
@ -283,6 +279,11 @@ public class Daemon extends SiteProgram {
|
|||
.setDbCfgInjector(dbInjector, cfgInjector);
|
||||
manager.add(dbInjector, cfgInjector, sysInjector);
|
||||
|
||||
if (!consoleLog) {
|
||||
manager.add(ErrorLogFile.start(getSitePath(),
|
||||
cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class))));
|
||||
}
|
||||
|
||||
sshd &= !sshdOff();
|
||||
if (sshd) {
|
||||
initSshd();
|
||||
|
|
|
@ -19,17 +19,21 @@ import com.google.gerrit.extensions.events.LifecycleListener;
|
|||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.util.SystemLog;
|
||||
|
||||
import net.logstash.log4j.JSONEventLayoutV1;
|
||||
|
||||
import org.apache.log4j.ConsoleAppender;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ErrorLogFile {
|
||||
static final String LOG_NAME = "error_log";
|
||||
static final String JSON_SUFFIX = ".json";
|
||||
|
||||
public static void errorOnlyConsole() {
|
||||
LogManager.resetConfiguration();
|
||||
|
@ -47,12 +51,12 @@ public class ErrorLogFile {
|
|||
root.addAppender(dst);
|
||||
}
|
||||
|
||||
public static LifecycleListener start(final Path sitePath)
|
||||
public static LifecycleListener start(final Path sitePath, final Config config)
|
||||
throws IOException {
|
||||
Path logdir = FileUtil.mkdirsOrDie(new SitePaths(sitePath).logs_dir,
|
||||
"Cannot create log directory");
|
||||
if (SystemLog.shouldConfigure()) {
|
||||
initLogSystem(logdir);
|
||||
initLogSystem(logdir, config);
|
||||
}
|
||||
|
||||
return new LifecycleListener() {
|
||||
|
@ -67,10 +71,21 @@ public class ErrorLogFile {
|
|||
};
|
||||
}
|
||||
|
||||
private static void initLogSystem(Path logdir) {
|
||||
private static void initLogSystem(Path logdir, Config config) {
|
||||
final Logger root = LogManager.getRootLogger();
|
||||
root.removeAllAppenders();
|
||||
root.addAppender(SystemLog.createAppender(logdir, LOG_NAME,
|
||||
new PatternLayout("[%d] %-5p %c %x: %m%n")));
|
||||
|
||||
boolean json = config.getBoolean("log", "jsonLogging", false);
|
||||
boolean text = config.getBoolean("log", "textLogging", true) || !json;
|
||||
|
||||
if (text) {
|
||||
root.addAppender(SystemLog.createAppender(logdir, LOG_NAME,
|
||||
new PatternLayout("[%d] %-5p %c %x: %m%n")));
|
||||
}
|
||||
|
||||
if (json) {
|
||||
root.addAppender(SystemLog.createAppender(logdir, LOG_NAME + JSON_SUFFIX,
|
||||
new JSONEventLayoutV1()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue