aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-maven3-plugin/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-10-09 21:59:39 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-10-09 22:31:55 +0200
commitb98f0e47c293c77dfee8b2b96cce450cbf540a20 (patch)
tree7bbb71b6d8a48c87528524b6e43534482a10b4fc /sonar-maven3-plugin/src
parentb8135c03e29c0cf49603435e598039a018851f41 (diff)
downloadsonarqube-b98f0e47c293c77dfee8b2b96cce450cbf540a20.tar.gz
sonarqube-b98f0e47c293c77dfee8b2b96cce450cbf540a20.zip
SONAR-2719 add timestamp to maven logs
Diffstat (limited to 'sonar-maven3-plugin/src')
-rw-r--r--sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java38
-rw-r--r--sonar-maven3-plugin/src/main/resources/org/sonar/maven3/logback.xml14
2 files changed, 23 insertions, 29 deletions
diff --git a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java
index 001378c7bb7..eabc913e42a 100644
--- a/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java
+++ b/sonar-maven3-plugin/src/main/java/org/sonar/maven3/SonarMojo.java
@@ -19,10 +19,6 @@
*/
package org.sonar.maven3;
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.core.joran.spi.JoranException;
-import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -36,14 +32,12 @@ import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.batch.Batch;
import org.sonar.batch.MavenProjectConverter;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
-
-import java.io.InputStream;
+import org.sonar.core.config.Logback;
/**
* @goal sonar
@@ -74,7 +68,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact factory to use.
- *
+ *
* @component
* @required
* @readonly
@@ -83,7 +77,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact repository to use.
- *
+ *
* @parameter expression="${localRepository}"
* @required
* @readonly
@@ -92,7 +86,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact metadata source to use.
- *
+ *
* @component
* @required
* @readonly
@@ -101,7 +95,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact collector to use.
- *
+ *
* @component
* @required
* @readonly
@@ -110,7 +104,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The dependency tree builder to use.
- *
+ *
* @component
* @required
* @readonly
@@ -132,7 +126,7 @@ public final class SonarMojo extends AbstractMojo {
private RuntimeInformation runtimeInformation;
public void execute() throws MojoExecutionException, MojoFailureException {
- initLogging();
+ configureLogback();
executeBatch();
}
@@ -152,22 +146,8 @@ public final class SonarMojo extends AbstractMojo {
return new EnvironmentInformation("Maven", mavenVersion);
}
- private void initLogging() throws MojoExecutionException {
- LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
- JoranConfigurator jc = new JoranConfigurator();
- jc.setContext(context);
- context.reset();
- InputStream input = getClass().getResourceAsStream("/org/sonar/batch/logback.xml");
+ private void configureLogback() {
System.setProperty("ROOT_LOGGER_LEVEL", getLog().isDebugEnabled() ? "DEBUG" : "INFO");
- try {
- jc.doConfigure(input);
-
- } catch (JoranException e) {
- throw new MojoExecutionException("can not initialize logging", e);
-
- } finally {
- IOUtils.closeQuietly(input);
- }
+ Logback.configure("/org/sonar/maven3/logback.xml");
}
-
}
diff --git a/sonar-maven3-plugin/src/main/resources/org/sonar/maven3/logback.xml b/sonar-maven3-plugin/src/main/resources/org/sonar/maven3/logback.xml
new file mode 100644
index 00000000000..585dc31806e
--- /dev/null
+++ b/sonar-maven3-plugin/src/main/resources/org/sonar/maven3/logback.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<configuration debug="false">
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>[%level] %d{HH:mm:ss.SSS} %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <!-- Include definition of loggers. The appender STDOUT is not shared in sonar-batch because
+ format is slightly different between Maven and Ant logs -->
+ <include resource="/org/sonar/batch/logback-base.xml"/>
+
+</configuration> \ No newline at end of file