aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java2
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java1
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java2
-rw-r--r--server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java1
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java11
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchServer.java2
-rw-r--r--server/sonar-search/src/main/resources/org/sonar/search/logback.xml16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/Logging.java12
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/platform/logback.xml30
-rw-r--r--sonar-application/src/main/java/org/sonar/application/App.java6
-rw-r--r--sonar-application/src/main/resources/org/sonar/application/logback.xml33
-rw-r--r--sonar-core/src/main/java/org/sonar/core/config/DebtProperties.java7
-rw-r--r--sonar-core/src/main/java/org/sonar/core/config/Logback.java26
13 files changed, 62 insertions, 87 deletions
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 c0909a93fb5..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
@@ -19,8 +19,11 @@
*/
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;
@@ -43,6 +46,14 @@ public class ProcessLogging {
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
+ public void addConsoleAppender() {
+ Logger consoleLogger = (Logger) LoggerFactory.getLogger("console");
+ Appender<ILoggingEvent> consoleAppender = consoleLogger.getAppender("CONSOLE");
+
+ Logger gobblerLogger = (Logger) LoggerFactory.getLogger("gobbler");
+ gobblerLogger.addAppender(consoleAppender);
+ }
+
/**
* Extracted only for unit testing
*/
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 f74d51fce42..2f556aeb1b9 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
@@ -267,7 +267,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 648ece82e28..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
@@ -9,27 +9,17 @@
<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
+ %d{yyyy.MM.dd HH:mm:ss} %-5level sea[%logger{20}] %X %msg%n
</pattern>
</encoder>
</appender>
<root>
<level value="INFO"/>
- <appender-ref ref="LOGFILE"/>
+ <appender-ref ref="CONSOLE"/>
</root>
</configuration>
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<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);
}
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 4607ddb23bf..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
@@ -9,40 +9,14 @@
<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}
+ ${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"/>
@@ -93,7 +67,7 @@
<root>
<level value="INFO"/>
- <appender-ref ref="LOGFILE"/>
+ <appender-ref ref="CONSOLE"/>
</root>
</configuration>
diff --git a/sonar-application/src/main/java/org/sonar/application/App.java b/sonar-application/src/main/java/org/sonar/application/App.java
index bba2dd73069..502cf561394 100644
--- a/sonar-application/src/main/java/org/sonar/application/App.java
+++ b/sonar-application/src/main/java/org/sonar/application/App.java
@@ -109,7 +109,11 @@ public class App implements Stoppable {
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);
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 246afdf89f3..cbcd991ded9 100644
--- a/sonar-application/src/main/resources/org/sonar/application/logback.xml
+++ b/sonar-application/src/main/resources/org/sonar/application/logback.xml
@@ -3,17 +3,46 @@
<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>%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>
- %d{yyyy.MM.dd HH:mm:ss} %-5level %msg%n
+ %msg%n
</pattern>
</encoder>
</appender>
+ <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="CONSOLE"/>
+ <appender-ref ref="APP"/>
</root>
</configuration>
diff --git a/sonar-core/src/main/java/org/sonar/core/config/DebtProperties.java b/sonar-core/src/main/java/org/sonar/core/config/DebtProperties.java
index 035cfcb01e7..e53e113c708 100644
--- a/sonar-core/src/main/java/org/sonar/core/config/DebtProperties.java
+++ b/sonar-core/src/main/java/org/sonar/core/config/DebtProperties.java
@@ -67,10 +67,11 @@ class DebtProperties {
PropertyDefinition.builder(CoreProperties.RATING_GRID)
.defaultValue("" + CoreProperties.RATING_GRID_DEF_VALUES)
.name("Rating grid")
- .description("SQALE ratings range from A (very good) to E (very bad). They compare the technical debt on a project to the time that has already gone into writing it. " +
+ .description("SQALE ratings range from A (very good) to E (very bad). The rating is determined by the value of the Technical Debt Ratio, " +
+ "which compares the technical debt on a project to the cost it would take to rewrite the code from scratch. " +
"The default values for A through D are 0.1,0.2,0.5,1. Anything over 1 is an E. " +
- "Assuming the size metric is lines of code (LOC), and the work unit is 30 (minutes to produce 1 LOC), " +
- "a project with a technical debt of 24,000 minutes for 2,500 LOC will have a ratio of 24000/(30 * 2,500) = 0.32. That yields a SQALE rating of C.")
+ "Example: assuming the size metric is lines of code (LOC), and the work unit is 30 (minutes to produce 1 LOC), " +
+ "a project with a technical debt of 24,000 minutes for 2,500 LOC will have a technical debt ratio of 24000/(30 * 2,500) = 0.32. That yields a SQALE rating of C.")
.category(CoreProperties.CATEGORY_TECHNICAL_DEBT)
.deprecatedKey("ratingGrid")
.build(),
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<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);
}