*/
package org.sonar.process;
+import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
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.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import org.slf4j.LoggerFactory;
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
+ public void addConsoleAppender() {
+ Logger consoleLogger = (Logger) LoggerFactory.getLogger("console");
+ Appender<ILoggingEvent> consoleAppender = consoleLogger.getAppender("CONSOLE");
+
+ Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ rootLogger.addAppender(consoleAppender);
+ }
+
/**
* Extracted only for unit testing
*/
<configuration debug="false">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
- <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <File>${sonar.path.logs}/search.log</File>
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <param name="FileNamePattern" value="${sonar.path.logs}/search.%i.log"/>
- <param name="MinIndex" value="1"/>
- <param name="MaxIndex" value="3"/>
- </rollingPolicy>
- <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <param name="MaxFileSize" value="5MB"/>
- </triggeringPolicy>
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <!-- Use %d{yyyy.MM.dd HH:mm:ss.SSS} to display milliseconds -->
<pattern>
%d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %X %msg%n
</pattern>
<root>
<level value="INFO"/>
- <appender-ref ref="LOGFILE"/>
+ <appender-ref ref="CONSOLE"/>
</root>
</configuration>
<configuration debug="false">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
- <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <File>${sonar.path.logs}/sonar.log</File>
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <param name="FileNamePattern" value="${sonar.path.logs}/sonar.%i.log"/>
- <param name="MinIndex" value="1"/>
- <param name="MaxIndex" value="3"/>
- </rollingPolicy>
- <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <param name="MaxFileSize" value="5MB"/>
- </triggeringPolicy>
- <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <!-- Use %d{yyyy.MM.dd HH:mm:ss.SSS} to display milliseconds -->
- <pattern>
- ${LOGFILE_LOGGING_FORMAT}
- </pattern>
- </encoder>
- </appender>
-
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
- <level>WARN</level>
- </filter>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
- ${CONSOLE_LOGGING_FORMAT}
+ ${LOGFILE_LOGGING_FORMAT}
</pattern>
</encoder>
</appender>
- <logger name="console" additivity="false">
- <level value="INFO"/>
- <appender-ref ref="CONSOLE"/>
- </logger>
-
<!-- Display Rails warnings and errors -->
<logger name="rails">
<level value="WARN"/>
<root>
<level value="INFO"/>
- <appender-ref ref="LOGFILE"/>
+ <appender-ref ref="CONSOLE"/>
</root>
</configuration>
CommandLineParser cli = new CommandLineParser();
Properties rawProperties = cli.parseArguments(args);
Props props = new PropsBuilder(rawProperties, new JdbcSettings()).build();
- new ProcessLogging().configure(props, "/org/sonar/application/logback.xml");
+ ProcessLogging logging = new ProcessLogging();
+ logging.configure(props, "/org/sonar/application/logback.xml");
+ if (props.valueAsBoolean("sonar.log.console", false)) {
+ logging.addConsoleAppender();
+ }
App app = new App();
app.start(props);
<configuration debug="false">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
+ <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <File>${sonar.path.logs}/sonar.log</File>
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <param name="FileNamePattern" value="${sonar.path.logs}/sonar.%i.log"/>
+ <param name="MinIndex" value="1"/>
+ <param name="MaxIndex" value="5"/>
+ </rollingPolicy>
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <param name="MaxFileSize" value="10MB"/>
+ </triggeringPolicy>
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>%3.3logger %msg%n</pattern>
+ </encoder>
+ </appender>
+
<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 %msg%n
+ app %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %msg%n
</pattern>
</encoder>
</appender>
+ <logger name="console">
+ <appender-ref ref="CONSOLE"/>
+ </logger>
+
<root>
<level value="INFO"/>
- <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="LOGFILE"/>
</root>
</configuration>