aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main/src/main
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2021-08-05 09:30:32 +0200
committersonartech <sonartech@sonarsource.com>2021-08-11 20:08:08 +0000
commitbb03cec435d188cc7fd5576eced84eaa2c634212 (patch)
treeb3f3af3322a77964aa06ef4e5e3e2d46208f1703 /server/sonar-main/src/main
parent8bda059b8117593fac19e34cafb41c5d0be76a54 (diff)
downloadsonarqube-bb03cec435d188cc7fd5576eced84eaa2c634212.tar.gz
sonarqube-bb03cec435d188cc7fd5576eced84eaa2c634212.zip
SONAR-15243 Enable JSON logging on Elasticsearch process
Diffstat (limited to 'server/sonar-main/src/main')
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/es/EsLogging.java34
1 files changed, 20 insertions, 14 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsLogging.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsLogging.java
index 47c8a675a99..75e105fa18b 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/es/EsLogging.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsLogging.java
@@ -30,6 +30,7 @@ import org.sonar.process.logging.LogLevelConfig;
import org.sonar.process.logging.RootLoggerConfig;
import static org.sonar.process.ProcessProperties.Property.LOG_CONSOLE;
+import static org.sonar.process.ProcessProperties.Property.LOG_JSON_OUTPUT;
import static org.sonar.process.logging.RootLoggerConfig.newRootLoggerConfigBuilder;
public class EsLogging {
@@ -39,21 +40,26 @@ public class EsLogging {
RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessId(ProcessId.ELASTICSEARCH).build();
String logPattern = log4JPropertiesBuilder.buildLogPattern(config);
- log4JPropertiesBuilder.internalLogLevel(Level.ERROR);
- log4JPropertiesBuilder.configureGlobalFileLog(config, logDir, logPattern);
- if (isAllLogsToConsoleEnabled(props)) {
- log4JPropertiesBuilder.configureGlobalStdoutLog(logPattern);
- }
- log4JPropertiesBuilder.apply(
- LogLevelConfig.newBuilder(log4JPropertiesBuilder.getRootLoggerName())
- .rootLevelFor(ProcessId.ELASTICSEARCH)
- // turn off ES type deprecation logging to not flood logs
- .immutableLevel("DEPRECATION", Level.ERROR)
- .immutableLevel("org.elasticsearch.deprecation", Level.ERROR)
- .immutableLevel("org.elasticsearch.client.RestClient", Level.ERROR)
- .build());
+ return log4JPropertiesBuilder.internalLogLevel(Level.ERROR)
+ .rootLoggerConfig(config)
+ .logPattern(logPattern)
+ .enableAllLogsToConsole(isAllLogsToConsoleEnabled(props))
+ .jsonOutput(isJsonOutput(props))
+ .logDir(logDir)
+ .logLevelConfig(
+ LogLevelConfig.newBuilder(log4JPropertiesBuilder.getRootLoggerName())
+ .rootLevelFor(ProcessId.ELASTICSEARCH)
+ // turn off ES type deprecation logging to not flood logs
+ .immutableLevel("DEPRECATION", Level.ERROR)
+ .immutableLevel("org.elasticsearch.deprecation", Level.ERROR)
+ .immutableLevel("org.elasticsearch.client.RestClient", Level.ERROR)
+ .build())
+ .build();
+ }
- return log4JPropertiesBuilder.get();
+ private static boolean isJsonOutput(Props props) {
+ return props.valueAsBoolean(LOG_JSON_OUTPUT.getKey(),
+ Boolean.parseBoolean(LOG_JSON_OUTPUT.getDefaultValue()));
}
/**