--- /dev/null
+<included>
+ <logger name="org.hibernate">
+ <level value="WARN"/>
+ </logger>
+
+ <!-- set DEBUG to activate SQL logs. NOT RECOMMENDED -->
+ <logger name="org.hibernate.SQL">
+ <level value="ERROR"/>
+ </logger>
+
+ <!-- set INFO to activate SQL statistics. NOT RECOMMENDED -->
+ <logger name="org.sonar.DBSTATISTICS">
+ <level value="ERROR"/>
+ </logger>
+
+ <logger name="net.sf.ehcache">
+ <level value="WARN"/>
+ </logger>
+
+ <logger name="org.hibernate.cache.ReadWriteCache">
+ <!-- removing "An item was expired by the cache while it was locked (increase your cache timeout)" msg -->
+ <level value="ERROR"/>
+ </logger>
+ <logger name="org.hibernate.cache.EhCacheProvider">
+ <!-- removing "org.hibernate.cache.EhCacheProvider - Could not find configuratio)" message -->
+ <level value="ERROR"/>
+ </logger>
+
+ <root>
+ <level value="${ROOT_LOGGER_LEVEL}"/>
+ <appender-ref ref="STDOUT"/>
+ </root>
+</included>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
-
<configuration debug="false">
+ <!--
+ This file is directly loaded by Sonar Ant Task 1.1 and Sonar Runner 1.1.
+ Inclusion of logback-base.xml is not supported by these 2 versions, so loggers must
+ be duplicated.
+ -->
+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <pattern>[%level] %X{module} %msg%n</pattern>
- </layout>
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %msg%n</pattern>
+ </encoder>
</appender>
<logger name="org.hibernate">
<level value="ERROR"/>
</logger>
- <!-- see org.sonar.mojo.InternalMojo#initLogging -->
<root>
<level value="${ROOT_LOGGER_LEVEL}"/>
<appender-ref ref="STDOUT"/>
</root>
-
+
</configuration>
\ No newline at end of file
<artifactId>commons-dbcp</artifactId>
</dependency>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>log4j-over-slf4j</artifactId>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.config;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Configure Logback
+ *
+ * @since 2.12
+ */
+public final class Logback {
+
+ public static void configure(String classloaderPath) {
+ InputStream input = Logback.class.getResourceAsStream(classloaderPath);
+ if (input == null) {
+ throw new IllegalArgumentException("Logback configuration not found in classloader: " + classloaderPath);
+ }
+ configure(input);
+ }
+
+ public static void configure(File logbackFile) {
+ try {
+ FileInputStream input = FileUtils.openInputStream(logbackFile);
+ configure(input);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Fail to load the Logback configuration: " + logbackFile, e);
+ }
+ }
+
+ /**
+ * Note that this method closes the input stream
+ */
+ private static void configure(InputStream input) {
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ lc.reset();
+ configurator.doConfigure(input);
+ } catch (JoranException e) {
+ // StatusPrinter will handle this
+ } finally {
+ IOUtils.closeQuietly(input);
+ }
+ StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
+ }
+}
*/
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;
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
/**
* The artifact factory to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The artifact repository to use.
- *
+ *
* @parameter expression="${localRepository}"
* @required
* @readonly
/**
* The artifact metadata source to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The artifact collector to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The dependency tree builder to use.
- *
+ *
* @component
* @required
* @readonly
private RuntimeInformation runtimeInformation;
public void execute() throws MojoExecutionException, MojoFailureException {
- initLogging();
+ configureLogback();
executeBatch();
}
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");
}
}
--- /dev/null
+<?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
*/
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;
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
/**
* The artifact factory to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The artifact repository to use.
- *
+ *
* @parameter expression="${localRepository}"
* @required
* @readonly
/**
* The artifact metadata source to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The artifact collector to use.
- *
+ *
* @component
* @required
* @readonly
/**
* The dependency tree builder to use.
- *
+ *
* @component
* @required
* @readonly
private RuntimeInformation runtimeInformation;
public void execute() throws MojoExecutionException, MojoFailureException {
- initLogging();
+ configureLogback();
executeBatch();
}
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");
}
-
}
--- /dev/null
+<?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
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
</dependency>
-
- <!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
- </dependency>
-
-
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.server.platform;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.core.joran.spi.JoranException;
-import ch.qos.logback.core.util.StatusPrinter;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-
-/**
- * Configure Logback with $SONAR_HOME/conf/logback.xml
- *
- * @since 2.12
- */
-final class Logback {
-
- static void configure() {
- configure(new File(SonarHome.getHome(), "conf/logback.xml"));
- }
-
- static void configure(File logbackFile) {
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- try {
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- lc.reset();
- configurator.doConfigure(logbackFile);
- } catch (JoranException e) {
- // StatusPrinter will handle this
- }
- StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
- }
-}
*/
package org.sonar.server.platform;
+import org.sonar.core.config.Logback;
+
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import java.io.File;
public final class PlatformLifecycleListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
- Logback.configure();
+ configureLogback();
Platform.getInstance().init(event.getServletContext());
Platform.getInstance().start();
}
public void contextDestroyed(ServletContextEvent event) {
Platform.getInstance().stop();
}
+
+ /**
+ * Configure Logback with $SONAR_HOME/conf/logback.xml
+ */
+ private void configureLogback() {
+ Logback.configure(new File(SonarHome.getHome(), "conf/logback.xml"));
+ }
}