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());
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.
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) {
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));
}
}
}
Logger consoleLogger = (Logger) LoggerFactory.getLogger("console");
Appender<ILoggingEvent> 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);
}
/**
@Override
public synchronized void stop() {
- if (!node.isClosed()) {
+ if (node != null && !node.isClosed()) {
node.close();
}
}
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
- %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
</pattern>
</encoder>
</appender>
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";
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<String, String> 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);
}
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
- ${LOGFILE_LOGGING_FORMAT}
+ ${LOGGING_FORMAT}
</pattern>
</encoder>
</appender>
<param name="MaxFileSize" value="10MB"/>
</triggeringPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <pattern>%3.3logger %msg%n</pattern>
+ <pattern>%msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="APP" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>%d{yyyy.MM.dd HH:mm:ss} %-5level app[%logger{20}] %msg%n</pattern>
</encoder>
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
- app %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %msg%n
+ %msg%n
</pattern>
</encoder>
</appender>
- <logger name="console">
+ <logger name="console" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
+ <logger name="gobbler" additivity="false">
+ <appender-ref ref="LOGFILE"/>
+ </logger>
+
<root>
<level value="INFO"/>
- <appender-ref ref="LOGFILE"/>
+ <appender-ref ref="APP"/>
</root>
</configuration>
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;
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 {
return context;
}
- private static Boolean isConsoleEnabled(Map<String, String> substitutionVariables) {
- return Boolean.valueOf(substitutionVariables.get("CONSOLE_ENABLED"));
- }
-
- private static Appender<ILoggingEvent> consoleAppender(LoggerContext context, Map<String, String> substitutionVariables) {
- PatternLayoutEncoder encoder = new PatternLayoutEncoder();
- encoder.setPattern(substitutionVariables.get("CONSOLE_LOGGING_FORMAT"));
- encoder.setContext(context);
- encoder.start();
- ConsoleAppender<ILoggingEvent> console = new ConsoleAppender<ILoggingEvent>();
- 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);
}