summaryrefslogtreecommitdiffstats
path: root/sonar-maven-plugin
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-maven-plugin
parentb8135c03e29c0cf49603435e598039a018851f41 (diff)
downloadsonarqube-b98f0e47c293c77dfee8b2b96cce450cbf540a20.tar.gz
sonarqube-b98f0e47c293c77dfee8b2b96cce450cbf540a20.zip
SONAR-2719 add timestamp to maven logs
Diffstat (limited to 'sonar-maven-plugin')
-rw-r--r--sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java45
-rw-r--r--sonar-maven-plugin/src/main/resources/org/sonar/maven/logback.xml14
2 files changed, 23 insertions, 36 deletions
diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
index 6b78f9b463d..89b5190ba97 100644
--- a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
+++ b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
@@ -19,11 +19,6 @@
*/
package org.sonar.maven;
-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.configuration.*;
-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;
@@ -38,13 +33,12 @@ import org.apache.maven.plugin.PluginManager;
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
@@ -81,7 +75,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact factory to use.
- *
+ *
* @component
* @required
* @readonly
@@ -90,7 +84,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact repository to use.
- *
+ *
* @parameter expression="${localRepository}"
* @required
* @readonly
@@ -99,7 +93,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact metadata source to use.
- *
+ *
* @component
* @required
* @readonly
@@ -108,7 +102,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The artifact collector to use.
- *
+ *
* @component
* @required
* @readonly
@@ -117,7 +111,7 @@ public final class SonarMojo extends AbstractMojo {
/**
* The dependency tree builder to use.
- *
+ *
* @component
* @required
* @readonly
@@ -139,7 +133,7 @@ public final class SonarMojo extends AbstractMojo {
private RuntimeInformation runtimeInformation;
public void execute() throws MojoExecutionException, MojoFailureException {
- initLogging();
+ configureLogback();
executeBatch();
}
@@ -159,29 +153,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);
- }
- }
-
- private Configuration getInitialConfiguration() {
- CompositeConfiguration configuration = new CompositeConfiguration();
- configuration.addConfiguration(new SystemConfiguration());
- configuration.addConfiguration(new EnvironmentConfiguration());
- configuration.addConfiguration(new MapConfiguration(project.getModel().getProperties()));
- return configuration;
+ Logback.configure("/org/sonar/maven/logback.xml");
}
}
diff --git a/sonar-maven-plugin/src/main/resources/org/sonar/maven/logback.xml b/sonar-maven-plugin/src/main/resources/org/sonar/maven/logback.xml
new file mode 100644
index 00000000000..585dc31806e
--- /dev/null
+++ b/sonar-maven-plugin/src/main/resources/org/sonar/maven/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