From: Simon Brandhof Date: Wed, 24 Sep 2014 16:19:50 +0000 (+0200) Subject: SONAR-5621 Merge server log files into a single one X-Git-Tag: 4.5-RC3~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=85c037c87a728edbefc0fd417d6cb89cab246e44;p=sonarqube.git SONAR-5621 Merge server log files into a single one --- diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java index 77a4b607d0d..3cedc1c9c84 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java @@ -49,7 +49,7 @@ public class JavaProcessLauncher { commands.prepare(); ProcessBuilder processBuilder = create(command); - LoggerFactory.getLogger(getClass()).info("Launch {}: {}", + LoggerFactory.getLogger(getClass()).info("Launch process[{}]: {}", command.getKey(), StringUtils.join(processBuilder.command(), " ")); process = processBuilder.start(); StreamGobbler inputGobbler = new StreamGobbler(process.getInputStream(), command.getKey()); diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java index 672fdf6cb6c..31eae8e9ba3 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java @@ -90,7 +90,6 @@ class ProcessRef { ProcessUtils.sendKillSignal(process); // signal is sent, waiting for shutdown hooks to be executed (or not... it depends on OS) process.waitFor(); - LoggerFactory.getLogger(getClass()).info(String.format("%s is stopped", this)); } catch (InterruptedException ignored) { // can't wait for the termination of process. Let's assume it's down. diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java index d5f54e33248..2115884b189 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java @@ -38,7 +38,7 @@ class StreamGobbler extends Thread { private final Logger logger; StreamGobbler(InputStream is, String processKey) { - this(is, processKey, LoggerFactory.getLogger(processKey)); + this(is, processKey, LoggerFactory.getLogger("gobbler")); } StreamGobbler(InputStream is, String processKey, Logger logger) { diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java index b40291f164a..a774868f75a 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java @@ -68,6 +68,7 @@ class TerminatorThread extends Thread { LoggerFactory.getLogger(getClass()).info(String.format("%s failed to stop in a timely fashion. Killing it.", ref)); } ref.stop(); + LoggerFactory.getLogger(getClass()).info(String.format("%s is stopped", ref)); } } } diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java index 18893090bf3..2fb7baa865e 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java @@ -50,8 +50,8 @@ public class ProcessLogging { Logger consoleLogger = (Logger) LoggerFactory.getLogger("console"); Appender consoleAppender = consoleLogger.getAppender("CONSOLE"); - Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); - rootLogger.addAppender(consoleAppender); + Logger gobblerLogger = (Logger) LoggerFactory.getLogger("gobbler"); + gobblerLogger.addAppender(consoleAppender); } /** diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java index cb039b55162..d63abe3b2b5 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java @@ -249,7 +249,7 @@ public class SearchServer implements Monitored { @Override public synchronized void stop() { - if (!node.isClosed()) { + if (node != null && !node.isClosed()) { node.close(); } } diff --git a/server/sonar-search/src/main/resources/org/sonar/search/logback.xml b/server/sonar-search/src/main/resources/org/sonar/search/logback.xml index d10553b643b..3c24d95cdc0 100644 --- a/server/sonar-search/src/main/resources/org/sonar/search/logback.xml +++ b/server/sonar-search/src/main/resources/org/sonar/search/logback.xml @@ -12,7 +12,7 @@ - %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %X %msg%n + %d{yyyy.MM.dd HH:mm:ss} %-5level sea[%logger{20}] %X %msg%n diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/Logging.java b/server/sonar-server/src/main/java/org/sonar/server/app/Logging.java index fefc1444a3b..e5d8c52b225 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/app/Logging.java +++ b/server/sonar-server/src/main/java/org/sonar/server/app/Logging.java @@ -37,20 +37,15 @@ import java.util.logging.LogManager; class Logging { - private static final String CONFIG_LOG_CONSOLE = "sonar.log.console"; - private static final String LOG_COMMON_PREFIX = "%d{yyyy.MM.dd HH:mm:ss} %-5level "; private static final String LOG_COMMON_SUFFIX = "%msg%n"; - private static final String LOG_LOGFILE_SPECIFIC_PART = "[%logger{20}] %X "; + private static final String LOG_LOGFILE_SPECIFIC_PART = "web[%logger{20}] %X "; private static final String LOG_FULL_SPECIFIC_PART = "%thread "; private static final String LOGFILE_STANDARD_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_LOGFILE_SPECIFIC_PART + LOG_COMMON_SUFFIX; private static final String LOGFILE_FULL_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_FULL_SPECIFIC_PART + LOG_LOGFILE_SPECIFIC_PART + LOG_COMMON_SUFFIX; - private static final String CONSOLE_STANDARD_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_COMMON_SUFFIX; - private static final String CONSOLE_FULL_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_FULL_SPECIFIC_PART + LOG_COMMON_SUFFIX; - static final String ACCESS_RELATIVE_PATH = "WEB-INF/config/logback-access.xml"; static final String PROPERTY_ENABLE_ACCESS_LOGS = "sonar.web.accessLogs.enable"; @@ -71,12 +66,9 @@ class Logging { private static void configureLogback(Props props) { String configProfilingLevel = props.value(Profiling.CONFIG_PROFILING_LEVEL, "NONE"); Profiling.Level profilingLevel = Profiling.Level.fromConfigString(configProfilingLevel); - String consoleEnabled = props.value(CONFIG_LOG_CONSOLE, "false"); Map variables = ImmutableMap.of( "sonar.path.logs", props.nonNullValue("sonar.path.logs"), - "LOGFILE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? LOGFILE_FULL_LOGGING_FORMAT : LOGFILE_STANDARD_LOGGING_FORMAT, - "CONSOLE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? CONSOLE_FULL_LOGGING_FORMAT : CONSOLE_STANDARD_LOGGING_FORMAT, - "CONSOLE_ENABLED", consoleEnabled); + "LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? LOGFILE_FULL_LOGGING_FORMAT : LOGFILE_STANDARD_LOGGING_FORMAT); Logback.configure("/org/sonar/server/platform/logback.xml", variables); } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/platform/logback.xml b/server/sonar-server/src/main/resources/org/sonar/server/platform/logback.xml index 84ce76baece..9dc53c89a8b 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/platform/logback.xml +++ b/server/sonar-server/src/main/resources/org/sonar/server/platform/logback.xml @@ -12,7 +12,7 @@ - ${LOGFILE_LOGGING_FORMAT} + ${LOGGING_FORMAT} diff --git a/sonar-application/src/main/resources/org/sonar/application/logback.xml b/sonar-application/src/main/resources/org/sonar/application/logback.xml index e34156819f0..cbcd991ded9 100644 --- a/sonar-application/src/main/resources/org/sonar/application/logback.xml +++ b/sonar-application/src/main/resources/org/sonar/application/logback.xml @@ -14,25 +14,35 @@ - %3.3logger %msg%n + %msg%n + + + + + + %d{yyyy.MM.dd HH:mm:ss} %-5level app[%logger{20}] %msg%n - app %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %msg%n + %msg%n - + + + + + - + diff --git a/sonar-core/src/main/java/org/sonar/core/config/Logback.java b/sonar-core/src/main/java/org/sonar/core/config/Logback.java index 9d2eb8332bb..ac9a7b4e00c 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/Logback.java +++ b/sonar-core/src/main/java/org/sonar/core/config/Logback.java @@ -20,13 +20,8 @@ package org.sonar.core.config; import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.classic.encoder.PatternLayoutEncoder; import ch.qos.logback.classic.joran.JoranConfigurator; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.Appender; -import ch.qos.logback.core.ConsoleAppender; import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.util.StatusPrinter; import org.apache.commons.io.FileUtils; @@ -74,11 +69,6 @@ public class Logback implements BatchComponent, ServerComponent { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(configureContext(lc, substitutionVariables)); configurator.doConfigure(input); - if (isConsoleEnabled(substitutionVariables)) { - Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); - rootLogger.setAdditive(false); - rootLogger.addAppender(consoleAppender(lc, substitutionVariables)); - } } catch (JoranException e) { // StatusPrinter will handle this } finally { @@ -95,22 +85,6 @@ public class Logback implements BatchComponent, ServerComponent { return context; } - private static Boolean isConsoleEnabled(Map substitutionVariables) { - return Boolean.valueOf(substitutionVariables.get("CONSOLE_ENABLED")); - } - - private static Appender consoleAppender(LoggerContext context, Map substitutionVariables) { - PatternLayoutEncoder encoder = new PatternLayoutEncoder(); - encoder.setPattern(substitutionVariables.get("CONSOLE_LOGGING_FORMAT")); - encoder.setContext(context); - encoder.start(); - ConsoleAppender console = new ConsoleAppender(); - console.setEncoder(encoder); - console.setContext(context); - console.start(); - return console; - } - public void setLoggerLevel(String loggerName, Level level) { ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(loggerName)).setLevel(level); }