aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-10-21 22:54:08 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-10-21 22:54:08 +0200
commit37f6f8a9efa236bf12cc3b1483ce100b2486774b (patch)
tree9a1571f2f1c9d649a0ca827f95572e536884de8d
parent0a22516b6569ebbc9ecc49c700c2e36f627c5077 (diff)
downloadsonarqube-37f6f8a9efa236bf12cc3b1483ce100b2486774b.tar.gz
sonarqube-37f6f8a9efa236bf12cc3b1483ce100b2486774b.zip
Log in console when server is up
-rw-r--r--sonar-application/src/main/assembly/conf/logback.xml30
-rw-r--r--sonar-application/src/main/assembly/conf/wrapper.conf2
-rw-r--r--sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java2
-rw-r--r--sonar-application/src/main/java/org/sonar/application/Logging.java16
-rw-r--r--sonar-application/src/test/java/org/sonar/application/LoggingTest.java13
-rw-r--r--sonar-application/src/test/java/org/sonar/application/StartServerTest.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java2
7 files changed, 37 insertions, 30 deletions
diff --git a/sonar-application/src/main/assembly/conf/logback.xml b/sonar-application/src/main/assembly/conf/logback.xml
index e2a2995e45c..f1f8178638e 100644
--- a/sonar-application/src/main/assembly/conf/logback.xml
+++ b/sonar-application/src/main/assembly/conf/logback.xml
@@ -9,7 +9,7 @@
<configuration debug="false">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
- <appender name="SONAR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${SONAR_HOME}/logs/sonar.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<param name="FileNamePattern" value="${SONAR_HOME}/logs/sonar.%i.log"/>
@@ -27,21 +27,23 @@
</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
+ </pattern>
+ </encoder>
+ </appender>
+
+ <logger name="console" additivity="false">
+ <level value="INFO"/>
+ <appender-ref ref="CONSOLE"/>
+ </logger>
+
<!-- Display Rails warnings and errors -->
- <logger name="rails" additivity="false">
+ <logger name="rails">
<level value="WARN"/>
- <appender-ref ref="SONAR_FILE"/>
- </logger>
- <!--
- Profiling of HTTP and SQL requests in Rails:
-
- <logger name="rails" additivity="false">
- <level value="DEBUG"/>
</logger>
-
- Example of command-line to get the HTTP requests with execution time greater than 10s :
- grep 'rails Completed in [0-9]\{5,\}ms' < sonar.log
- -->
<logger name="org.hibernate.cache.ReadWriteCache">
<!-- removing "An item was expired by the cache while it was locked (increase your cache timeout)" msg -->
@@ -82,7 +84,7 @@
<root>
<level value="INFO"/>
- <appender-ref ref="SONAR_FILE"/>
+ <appender-ref ref="LOGFILE"/>
</root>
</configuration>
diff --git a/sonar-application/src/main/assembly/conf/wrapper.conf b/sonar-application/src/main/assembly/conf/wrapper.conf
index 5dcff2c83cc..22ce7fc10d9 100644
--- a/sonar-application/src/main/assembly/conf/wrapper.conf
+++ b/sonar-application/src/main/assembly/conf/wrapper.conf
@@ -71,7 +71,7 @@ wrapper.console.loglevel=INFO
wrapper.logfile=../../logs/sonar.log
# Format of output for the log file. (See docs for formats)
-wrapper.logfile.format=TLM
+wrapper.logfile.format=M
# Log Level for log file output. (See docs for log levels)
wrapper.logfile.loglevel=INFO
diff --git a/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java b/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
index f50397a0a16..f20e6a3f8ad 100644
--- a/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
+++ b/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
@@ -42,7 +42,7 @@ class EmbeddedTomcat {
void start() throws IOException, LifecycleException {
if (tomcat != null || hook != null) {
- throw new IllegalStateException("Tomcat is already started");
+ throw new IllegalStateException("Server is already started");
}
// '%2F' (slash /) and '%5C' (backslash \) are permitted as path delimiters in URLs
diff --git a/sonar-application/src/main/java/org/sonar/application/Logging.java b/sonar-application/src/main/java/org/sonar/application/Logging.java
index cde5d970574..6cad075b6f5 100644
--- a/sonar-application/src/main/java/org/sonar/application/Logging.java
+++ b/sonar-application/src/main/java/org/sonar/application/Logging.java
@@ -42,11 +42,14 @@ class Logging {
static void configure(Tomcat tomcat, Env env, Props props) {
tomcat.setSilent(false);
- tomcat.getService().addLifecycleListener(new StartupLogger(LoggerFactory.getLogger(Logging.class)));
-
+ tomcat.getService().addLifecycleListener(new LifecycleLogger(console()));
configureLogbackAccess(tomcat, env, props);
}
+ static Logger console() {
+ return LoggerFactory.getLogger("console");
+ }
+
private static void configureLogbackAccess(Tomcat tomcat, Env env, Props props) {
if (props.booleanOf(PROPERTY_ENABLE_ACCESS_LOGS, true)) {
LogbackValve valve = new LogbackValve();
@@ -56,17 +59,20 @@ class Logging {
}
}
- static class StartupLogger implements LifecycleListener {
+ static class LifecycleLogger implements LifecycleListener {
private Logger logger;
- StartupLogger(Logger logger) {
+ LifecycleLogger(Logger logger) {
this.logger = logger;
}
@Override
public void lifecycleEvent(LifecycleEvent event) {
if ("after_start".equals(event.getType())) {
- logger.info("Web server is up");
+ logger.info("Web server is started");
+
+ } else if ("after_destroy".equals(event.getType())) {
+ logger.info("Web server is stopped");
}
}
}
diff --git a/sonar-application/src/test/java/org/sonar/application/LoggingTest.java b/sonar-application/src/test/java/org/sonar/application/LoggingTest.java
index 35e10890e55..55b9e4beab8 100644
--- a/sonar-application/src/test/java/org/sonar/application/LoggingTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/LoggingTest.java
@@ -31,11 +31,8 @@ import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
import org.slf4j.Logger;
-import java.io.File;
import java.util.Properties;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.*;
@@ -63,9 +60,9 @@ public class LoggingTest {
}
@Test
- public void log_when_started() {
+ public void log_when_started_and_stopped() {
Logger logger = mock(Logger.class);
- Logging.StartupLogger listener = new Logging.StartupLogger(logger);
+ Logging.LifecycleLogger listener = new Logging.LifecycleLogger(logger);
LifecycleEvent event = new LifecycleEvent(mock(Lifecycle.class), "before_init", null);
listener.lifecycleEvent(event);
@@ -73,6 +70,10 @@ public class LoggingTest {
event = new LifecycleEvent(mock(Lifecycle.class), "after_start", null);
listener.lifecycleEvent(event);
- verify(logger).info("Web server is up");
+ verify(logger).info("Web server is started");
+
+ event = new LifecycleEvent(mock(Lifecycle.class), "after_destroy", null);
+ listener.lifecycleEvent(event);
+ verify(logger).info("Web server is stopped");
}
}
diff --git a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
index e3aa3472023..1a7c9b7e769 100644
--- a/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/StartServerTest.java
@@ -114,7 +114,7 @@ public class StartServerTest {
starter.start();
fail();
} catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Tomcat is already started");
+ assertThat(e.getMessage()).isEqualTo("Server is already started");
started = true;
break;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 42797970a28..08809f8c276 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -410,12 +410,10 @@ public final class Platform {
public void stop() {
if (rootContainer != null) {
try {
- TimeProfiler profiler = new TimeProfiler().start("Stop server");
rootContainer.stopComponents();
rootContainer = null;
connected = false;
started = false;
- profiler.stop();
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).debug("Fail to stop server - ignored", e);
}