--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.microbenchmark;
+
+import org.apache.commons.lang.StringUtils;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.slf4j.Logger;
+
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Thread)
+@Fork(1)
+@Warmup(iterations = 3)
+@Measurement(iterations = 3)
+@BenchmarkMode(Mode.Throughput)
+public class LoggingBenchmark {
+
+ private Logger logger1 = org.slf4j.LoggerFactory.getLogger("microbenchmark1");
+ private Logger logger2 = org.slf4j.LoggerFactory.getLogger("microbenchmark2");
+
+ @Benchmark
+ public void logback_converters() throws Exception {
+ logger1.warn("many arguments {} {} {} {} {} {}", "foo", 7, 4.5, 1234567890L, true, new Date());
+ }
+
+ @Benchmark
+ public void string_converters() throws Exception {
+ logger2.warn(String.format("many arguments %s %d %f %d %b %tc", "foo", 7, 4.5, 1234567890L, true, new Date()));
+ }
+
+ @Benchmark
+ public void logback_no_args() throws Exception {
+ logger1.warn("no args");
+ StringUtils.replaceOnce()
+ }
+
+
+ /**
+ * You can this benchmark with maven command-line (see run.sh) or by executing this method
+ * in IDE
+ */
+ public static void main(String[] args) throws RunnerException {
+ Options opt = new OptionsBuilder()
+ .include(LoggingBenchmark.class.getSimpleName())
+ .build();
+ new Runner(opt).run();
+ }
+}
import org.apache.commons.lang.StringUtils;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.database.model.User;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.security.UserFinder;
import org.sonar.api.utils.SonarException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
import org.sonar.plugins.emailnotifications.api.EmailTemplate;
*/
public class EmailNotificationChannel extends NotificationChannel {
- private static final Logger LOG = LoggerFactory.getLogger(EmailNotificationChannel.class);
+ private static final Logger LOG = Loggers.get(EmailNotificationChannel.class);
/**
* @see org.apache.commons.mail.Email#setSocketConnectionTimeout(int)
import com.google.common.base.Splitter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
import java.io.File;
*/
public class CoveragePerTestSensor implements Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(CoveragePerTestSensor.class);
+ private static final Logger LOG = Loggers.get(CoveragePerTestSensor.class);
private static final String COVER_PER_TEST_EXTENSION = ".coveragePerTest";
import com.google.common.base.Splitter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
import java.io.File;
*/
public class DependencySensor implements Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(DependencySensor.class);
+ private static final Logger LOG = Loggers.get(DependencySensor.class);
private static final String DEPS_EXTENSION = ".deps";
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.batch.sensor.measure.NewMeasure;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
import java.io.File;
*/
public class MeasureSensor implements Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(MeasureSensor.class);
+ private static final Logger LOG = Loggers.get(MeasureSensor.class);
private static final String MEASURES_EXTENSION = ".measures";
import com.google.common.base.Splitter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.batch.sensor.symbol.Symbol;
import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
import java.io.File;
*/
public class SymbolReferencesSensor implements Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(SymbolReferencesSensor.class);
+ private static final Logger LOG = Loggers.get(SymbolReferencesSensor.class);
private static final String SYMBOL_EXTENSION = ".symbol";
import com.google.common.base.Splitter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
import org.sonar.api.batch.sensor.highlighting.TypeOfText;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
import java.io.File;
*/
public class SyntaxHighlightingSensor implements Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(SyntaxHighlightingSensor.class);
+ private static final Logger LOG = Loggers.get(SyntaxHighlightingSensor.class);
private static final String HIGHLIGHTING_EXTENSION = ".highlighting";
import com.google.common.base.Splitter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.batch.sensor.test.TestCaseExecution;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.xoo.Xoo;
import java.io.File;
*/
public class TestCaseSensor implements Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(TestCaseSensor.class);
+ private static final Logger LOG = Loggers.get(TestCaseSensor.class);
private static final String TESTPLAN_EXTENSION = ".testplan";
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
- <scope>provided</scope>
</dependency>
<!-- testing -->
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</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>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
package org.sonar.core.computation.dbcleaner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.ServerComponent;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.TimeUtils;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.purge.IdUuidPair;
import org.sonar.server.properties.ProjectSettingsFactory;
import javax.annotation.Nullable;
+
import java.util.Date;
import static org.sonar.core.purge.PurgeConfiguration.newDefaultPurgeConfiguration;
public class ProjectCleaner implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(ProjectCleaner.class);
+ private static final Logger LOG = Loggers.get(ProjectCleaner.class);
private final PurgeProfiler profiler;
private final PurgeListener purgeListener;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.FileUtils;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
webappContext = Webapp.configure(tomcat, props);
try {
tomcat.start();
- new StartupLogs(props, LoggerFactory.getLogger(getClass())).log(tomcat);
+ new StartupLogs(props, Loggers.get(getClass())).log(tomcat);
} catch (LifecycleException e) {
Throwables.propagate(e);
}
tomcat.stop();
tomcat.destroy();
} catch (Exception e) {
- LoggerFactory.getLogger(EmbeddedTomcat.class).error("Fail to stop web server", e);
+ Loggers.get(EmbeddedTomcat.class).error("Fail to stop web server", e);
}
}
FileUtils.deleteQuietly(tomcatBasedir());
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.lang.StringUtils;
import org.apache.coyote.http11.AbstractHttp11JsseProtocol;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import org.sonar.process.Props;
class StartupLogs {
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.startup.Tomcat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.process.LogbackHelper;
import org.sonar.process.Props;
void configure(Tomcat tomcat, Props props) {
tomcat.setSilent(true);
- tomcat.getService().addLifecycleListener(new LifecycleLogger(LoggerFactory.getLogger(TomcatAccessLog.class)));
+ tomcat.getService().addLifecycleListener(new LifecycleLogger(Loggers.get(TomcatAccessLog.class)));
configureLogbackAccess(tomcat, props);
}
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
if (props.valueAsBoolean("sonar.web.dev", false)) {
context.addParameter(RAILS_ENV, "development");
context.addParameter(JRUBY_MAX_RUNTIMES, "3");
- LoggerFactory.getLogger(Webapp.class).warn("WEB DEVELOPMENT MODE IS ENABLED - DO NOT USE FOR PRODUCTION USAGE");
+ Loggers.get(Webapp.class).warn("WEB DEVELOPMENT MODE IS ENABLED - DO NOT USE FOR PRODUCTION USAGE");
} else {
context.addParameter(RAILS_ENV, "production");
context.addParameter(JRUBY_MAX_RUNTIMES, "1");
if (StringUtils.isEmpty(webDir)) {
webDir = new File(props.value(ProcessConstants.PATH_HOME), "web").getAbsolutePath();
}
- LoggerFactory.getLogger(Webapp.class).info(String.format("Webapp directory: %s", webDir));
+ Loggers.get(Webapp.class).info(String.format("Webapp directory: %s", webDir));
return webDir;
}
}
package org.sonar.server.charts;
import com.google.common.collect.Maps;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.charts.Chart;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.CheckForNull;
+
import java.util.Map;
public final class ChartFactory implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(ChartFactory.class);
+ private static final Logger LOG = Loggers.get(ChartFactory.class);
private final Map<String, Chart> chartsByKey = Maps.newHashMap();
import com.google.common.collect.Maps;
import com.google.common.io.Closeables;
import org.jfree.chart.encoders.KeypointPNGEncoderAdapter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.charts.Chart;
import org.sonar.api.charts.ChartParameters;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.server.charts.deprecated.BarChart;
import org.sonar.server.charts.deprecated.BaseChartWeb;
import org.sonar.server.charts.deprecated.CustomBarChart;
public class ChartsServlet extends HttpServlet {
- private static final Logger LOG = LoggerFactory.getLogger(ChartsServlet.class);
+ private static final Logger LOG = Loggers.get(ChartsServlet.class);
private static final long serialVersionUID = 669857447198433893L;
@Override
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.component.Component;
import org.sonar.api.utils.Paging;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.util.Collection;
import java.util.List;
*/
public class DefaultComponentFinder {
- private static final Logger LOG = LoggerFactory.getLogger(DefaultComponentFinder.class);
+ private static final Logger LOG = Loggers.get(DefaultComponentFinder.class);
public DefaultComponentQueryResult find(ComponentQuery query, List<Component> allComponents) {
LOG.debug("ComponentQuery : {}", query);
import com.google.common.base.Throwables;
import org.apache.commons.lang.ArrayUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.activity.Activity;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.computation.db.AnalysisReportDto;
public class ComputationService implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(ComputationService.class);
+ private static final Logger LOG = Loggers.get(ComputationService.class);
private final DbClient dbClient;
private final ComputationSteps steps;
package org.sonar.server.computation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.computation.db.AnalysisReportDto;
import org.sonar.server.computation.step.ComputationSteps;
import org.sonar.server.platform.Platform;
* This thread pops queue of reports and processes the report if present
*/
public class ComputationThread implements Runnable {
- private static final Logger LOG = LoggerFactory.getLogger(ComputationThread.class);
+ private static final Logger LOG = Loggers.get(ComputationThread.class);
private final AnalysisReportQueue queue;
public ComputationThreadLauncher(AnalysisReportQueue queue) {
this.queue = queue;
- this.executorService = Executors.newSingleThreadScheduledExecutor(threadFactoryWithSpecificNameForLogging());
+ this.executorService = Executors.newSingleThreadScheduledExecutor(newThreadFactory());
this.delayBetweenTasks = 10;
this.delayForFirstStart = 0;
@VisibleForTesting
ComputationThreadLauncher(AnalysisReportQueue queue, long delayForFirstStart, long delayBetweenTasks, TimeUnit timeUnit) {
this.queue = queue;
- this.executorService = Executors.newSingleThreadScheduledExecutor(threadFactoryWithSpecificNameForLogging());
+ this.executorService = Executors.newSingleThreadScheduledExecutor(newThreadFactory());
this.delayBetweenTasks = delayBetweenTasks;
this.delayForFirstStart = delayForFirstStart;
executorService.scheduleAtFixedRate(new ComputationThread(queue), delayForFirstStart, delayBetweenTasks, timeUnit);
}
- /**
- * @see org.sonar.server.platform.SwitchLogbackAppender
- */
- private ThreadFactory threadFactoryWithSpecificNameForLogging() {
+ private ThreadFactory newThreadFactory() {
return new ThreadFactoryBuilder()
.setNameFormat(THREAD_NAME_PREFIX + "%d").setPriority(Thread.MIN_PRIORITY).build();
}
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Collections2;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.server.user.index.UserDoc;
import org.sonar.server.user.index.UserIndex;
import org.sonar.server.util.cache.CacheLoader;
private final UserIndex index;
public ScmAccountCacheLoader(UserIndex index) {
- this(index, LoggerFactory.getLogger(ScmAccountCacheLoader.class));
+ this(index, Loggers.get(ScmAccountCacheLoader.class));
}
@VisibleForTesting
package org.sonar.server.computation.step;
import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.TempFolder;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.protocol.output.BatchOutputReader;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.core.computation.db.AnalysisReportDto;
public class ParseReportStep implements ComputationStep {
- private static final Logger LOG = LoggerFactory.getLogger(ParseReportStep.class);
+ private static final Logger LOG = Loggers.get(ParseReportStep.class);
private final IssueComputation issueComputation;
private final DbClient dbClient;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.ibatis.session.ResultContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.Dto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.search.DbSynchronizationHandler;
import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.action.*;
+import org.sonar.server.search.action.DeleteKey;
+import org.sonar.server.search.action.DeleteNestedItem;
+import org.sonar.server.search.action.InsertDto;
+import org.sonar.server.search.action.RefreshIndex;
+import org.sonar.server.search.action.UpsertDto;
+import org.sonar.server.search.action.UpsertNestedItem;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.sql.Timestamp;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
*/
public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializable> implements Dao<DTO, KEY>, DaoComponent {
- private static final Logger LOGGER = LoggerFactory.getLogger(BaseDao.class);
+ private static final Logger LOGGER = Loggers.get(BaseDao.class);
protected IndexDefinition indexDefinition;
private Class<MAPPER> mapperClass;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.Database;
import org.sonar.core.persistence.dialect.H2;
public void start() {
try {
if (H2.ID.equals(db.getDialect().getId())) {
- LoggerFactory.getLogger(DatabaseChecker.class).warn("H2 database should be used for evaluation purpose only");
+ Loggers.get(DatabaseChecker.class).warn("H2 database should be used for evaluation purpose only");
} else if (Oracle.ID.equals(db.getDialect().getId())) {
checkOracleDriverVersion();
}
import org.h2.Driver;
import org.h2.tools.Server;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.utils.SonarException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.process.ProcessConstants;
import java.io.File;
import java.sql.SQLException;
public class EmbeddedDatabase implements Startable {
- private static final Logger LOG = LoggerFactory.getLogger(EmbeddedDatabase.class);
+ private static final Logger LOG = Loggers.get(EmbeddedDatabase.class);
private final Settings settings;
private Server server;
import org.apache.commons.dbutils.DbUtils;
import org.apache.ibatis.session.SqlSession;
import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.ServerComponent;
import org.sonar.api.platform.ServerUpgradeStatus;
import org.sonar.core.persistence.DdlUtils;
@VisibleForTesting
boolean createDatabase() {
if (DdlUtils.supportsDialect(dbClient.database().getDialect().getId()) && serverUpgradeStatus.isFreshInstall()) {
- LoggerFactory.getLogger(getClass()).info("Create database");
+ Loggers.get(getClass()).info("Create database");
SqlSession session = dbClient.openSession(false);
Connection connection = null;
try {
} catch (Exception e) {
// duplication between log and exception because webapp does not correctly log initial stacktrace
String msg = "Fail to execute database migration: " + className;
- LoggerFactory.getLogger(getClass()).error(msg, e);
+ Loggers.get(getClass()).error(msg, e);
throw new IllegalStateException(msg, e);
}
}
*/
package org.sonar.server.db.migrations;
-import org.slf4j.Logger;
+
+import org.sonar.api.utils.log.Logger;
import javax.annotation.CheckForNull;
*/
package org.sonar.server.db.migrations.v36;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicLong;
}
Progress(long totalViolations) {
- this(totalViolations, LoggerFactory.getLogger(Progress.class), System.currentTimeMillis());
+ this(totalViolations, Loggers.get(Progress.class), System.currentTimeMillis());
}
void increment(int delta) {
*/
package org.sonar.server.db.migrations.v36;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.Database;
import org.sonar.server.db.migrations.DatabaseMigration;
import org.sonar.server.db.migrations.SqlUtil;
*/
public class ViolationMigration implements DatabaseMigration {
- private static final Logger LOGGER = LoggerFactory.getLogger(ViolationMigration.class);
+ private static final Logger LOGGER = Loggers.get(ViolationMigration.class);
private static final String FAILURE_MESSAGE = "Fail to convert violations to issues";
import com.google.common.collect.Iterables;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ObjectUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.debt.DebtCharacteristic;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.ValidationMessages;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
public class DebtModelBackup implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(DebtModelBackup.class);
+ private static final Logger LOG = Loggers.get(DebtModelBackup.class);
private final DbClient dbClient;
private final DebtModelOperations debtModelOperations;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.server.util.ProgressLogger;
import java.util.List;
* </ul>
*/
public class BulkIndexer implements Startable {
- private static final Logger LOGGER = LoggerFactory.getLogger(BulkIndexer.class);
+ private static final Logger LOGGER = Loggers.get(BulkIndexer.class);
private static final long FLUSH_BYTE_SIZE = new ByteSizeValue(5, ByteSizeUnit.MB).bytes();
private static final String REFRESH_INTERVAL_SETTING = "index.refresh_interval";
private static final String ALREADY_STARTED_MESSAGE = "Bulk indexing is already started";
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.util.Map;
*/
public class IndexCreator implements ServerComponent, Startable {
- private static final Logger LOGGER = LoggerFactory.getLogger(IndexCreator.class);
+ private static final Logger LOGGER = Loggers.get(IndexCreator.class);
/**
* Internal setting stored on index to know its version. It's used to re-create index
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.IssueChangeContext;
import org.sonar.api.notifications.NotificationManager;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.issue.db.IssueDto;
import org.sonar.core.issue.db.IssueStorage;
public class IssueBulkChangeService {
- private static final Logger LOG = LoggerFactory.getLogger(IssueBulkChangeService.class);
+ private static final Logger LOG = Loggers.get(IssueBulkChangeService.class);
private final DbClient dbClient;
private final IssueService issueService;
import com.google.common.base.Joiner;
import org.apache.commons.lang.SystemUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.profiling.Profiling;
import org.sonar.core.profiling.Profiling.Level;
import org.sonar.core.profiling.StopWatch;
public class MeasureFilterEngine implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger("org.sonar.MEASURE_FILTER");
+ private static final Logger LOG = Loggers.get("org.sonar.MEASURE_FILTER");
private final MeasureFilterFactory factory;
private final MeasureFilterExecutor executor;
package org.sonar.server.notifications;
import com.google.common.collect.Lists;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.notifications.NotificationDispatcherMetadata;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.Nullable;
+
import java.util.Arrays;
import java.util.List;
*/
public class NotificationCenter implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(NotificationCenter.class);
+ private static final Logger LOG = Loggers.get(NotificationCenter.class);
private final NotificationDispatcherMetadata[] dispatchersMetadata;
private final NotificationChannel[] channels;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.ServerComponent;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.notifications.NotificationDispatcher;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.server.db.DbClient;
})
public class NotificationService implements ServerComponent, Startable {
- private static final Logger LOG = LoggerFactory.getLogger(NotificationService.class);
+ private static final Logger LOG = Loggers.get(NotificationService.class);
public static final String PROPERTY_DELAY = "sonar.notifications.delay";
public static final String PROPERTY_DELAY_BEFORE_REPORTING_STATUS = "sonar.notifications.runningDelayBeforeReportingStatus";
import org.apache.commons.dbutils.DbUtils;
import org.elasticsearch.index.query.QueryBuilders;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.core.persistence.DbSession;
}
public void clearIndexes() {
- LoggerFactory.getLogger(getClass()).info("Truncate Elasticsearch indices");
+ Loggers.get(getClass()).info("Truncate Elasticsearch indices");
try {
esClient.prepareClearCache()
.get();
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.CharEncoding;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.Nullable;
try {
jar.close();
} catch (Exception e) {
- LoggerFactory.getLogger(ClassLoaderUtils.class).error("Fail to close JAR file: " + jarPath, e);
+ Loggers.get(ClassLoaderUtils.class).error("Fail to close JAR file: " + jarPath, e);
}
}
}
package org.sonar.server.platform;
import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.MessageException;
import org.sonar.core.persistence.DatabaseVersion;
throw MessageException.of("Database relates to a more recent version of sonar. Please check your settings.");
}
if (status == DatabaseVersion.Status.REQUIRES_UPGRADE) {
- LoggerFactory.getLogger(DatabaseServerCompatibility.class).warn("Database must be upgraded. Please browse /setup");
+ Loggers.get(DatabaseServerCompatibility.class).warn("Database must be upgraded. Please browse /setup");
}
}
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerFileSystem;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.process.ProcessConstants;
import java.io.File;
*/
public class DefaultServerFileSystem implements ServerFileSystem, Startable {
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultServerFileSystem.class);
+ private static final Logger LOGGER = Loggers.get(DefaultServerFileSystem.class);
private final Server server;
private File homeDir;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.ServletFilter;
import javax.servlet.*;
List<Filter> filterList = Lists.newArrayList();
for (ServletFilter extension : filterExtensions) {
try {
- LoggerFactory.getLogger(MasterServletFilter.class).info(String.format("Initializing servlet filter %s [pattern=%s]", extension, extension.doGetPattern()));
+ Loggers.get(MasterServletFilter.class).info(String.format("Initializing servlet filter %s [pattern=%s]", extension, extension.doGetPattern()));
extension.init(config);
filterList.add(extension);
} catch (Exception e) {
*/
package org.sonar.server.platform;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.Server;
import org.sonar.core.persistence.DatabaseVersion;
dbConnected = false;
started = false;
} catch (Exception e) {
- LoggerFactory.getLogger(getClass()).debug("Fail to stop server - ignored", e);
+ Loggers.get(getClass()).debug("Fail to stop server - ignored", e);
}
}
}
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.Plugin;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
import org.sonar.api.platform.ServerFileSystem;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.Nullable;
+
import java.io.File;
import java.io.IOException;
*/
public class RailsAppsDeployer implements Startable {
- private static final Logger LOG = LoggerFactory.getLogger(RailsAppsDeployer.class);
+ private static final Logger LOG = Loggers.get(RailsAppsDeployer.class);
private static final String ROR_PATH = "org/sonar/ror/";
private final ServerFileSystem fileSystem;
import com.google.common.collect.Lists;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
}
}
} catch (SocketException e) {
- LoggerFactory.getLogger(ServerIdGenerator.class).error("Fail to browse network interfaces", e);
+ Loggers.get(ServerIdGenerator.class).error("Fail to browse network interfaces", e);
}
return result;
}
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.process.ProcessConstants;
import java.io.File;
import java.util.Properties;
public final class ServerImpl extends Server implements Startable {
- private static final Logger LOG = LoggerFactory.getLogger(ServerImpl.class);
+ private static final Logger LOG = Loggers.get(ServerImpl.class);
private final Settings settings;
private final Date startedAt;
package org.sonar.server.platform;
import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerStartHandler;
import org.sonar.api.platform.ServerStopHandler;
}
public void notifyStart() {
- LoggerFactory.getLogger(ServerLifecycleNotifier.class).debug("Notify " + ServerStartHandler.class.getSimpleName() + " handlers...");
+ Loggers.get(ServerLifecycleNotifier.class).debug("Notify " + ServerStartHandler.class.getSimpleName() + " handlers...");
for (ServerStartHandler handler : startHandlers) {
handler.onServerStart(server);
}
@Override
public void stop() {
- LoggerFactory.getLogger(ServerLifecycleNotifier.class).debug("Notify " + ServerStopHandler.class.getSimpleName() + " handlers...");
+ Loggers.get(ServerLifecycleNotifier.class).debug("Notify " + ServerStopHandler.class.getSimpleName() + " handlers...");
for (ServerStopHandler handler : stopHandlers) {
handler.onServerStop(server);
}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform;
-
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.Appender;
-import ch.qos.logback.core.AppenderBase;
-import ch.qos.logback.core.spi.AppenderAttachable;
-import ch.qos.logback.core.spi.AppenderAttachableImpl;
-import org.sonar.server.computation.ComputationThreadLauncher;
-
-import java.util.Iterator;
-
-public class SwitchLogbackAppender extends AppenderBase<ILoggingEvent> implements AppenderAttachable<ILoggingEvent> {
-
- private AppenderAttachableImpl<ILoggingEvent> attachedAppenders = new AppenderAttachableImpl<>();
- private Appender<ILoggingEvent> console = null;
- private Appender<ILoggingEvent> analysisReports = null;
-
- @Override
- protected void append(ILoggingEvent event) {
- if (Thread.currentThread().getName().startsWith(ComputationThreadLauncher.THREAD_NAME_PREFIX)) {
- analysisReports.doAppend(event);
- if (event.getLevel().isGreaterOrEqual(Level.WARN)) {
- console.doAppend(event);
- }
- } else {
- console.doAppend(event);
- }
- }
-
- @Override
- public void addAppender(Appender<ILoggingEvent> newAppender) {
- attachedAppenders.addAppender(newAppender);
- if ("CONSOLE".equals(newAppender.getName())) {
- console = newAppender;
- } else if ("ANALYSIS_REPORTS".equals(newAppender.getName())) {
- analysisReports = newAppender;
- } else {
- throw new IllegalArgumentException("Invalid appender name: " + newAppender.getName());
- }
- }
-
- @Override
- public Iterator<Appender<ILoggingEvent>> iteratorForAppenders() {
- return attachedAppenders.iteratorForAppenders();
- }
-
- @Override
- public Appender<ILoggingEvent> getAppender(String name) {
- return attachedAppenders.getAppender(name);
- }
-
- @Override
- public boolean isAttached(Appender<ILoggingEvent> appender) {
- return attachedAppenders.isAttached(appender);
- }
-
- @Override
- public void detachAndStopAllAppenders() {
- attachedAppenders.detachAndStopAllAppenders();
-
- }
-
- @Override
- public boolean detachAppender(Appender<ILoggingEvent> appender) {
- return attachedAppenders.detachAppender(appender);
- }
-
- @Override
- public boolean detachAppender(String name) {
- return attachedAppenders.detachAppender(name);
- }
-
-}
*/
package org.sonar.server.platform.ws;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.sonar.api.config.Settings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.platform.Platform;
@Override
public void handle(Request request, Response response) {
if (canRestart()) {
- Logger logger = LoggerFactory.getLogger(getClass());
+ Logger logger = Loggers.get(getClass());
logger.info("Restart server");
platform.restart();
logger.info("Server restarted");
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.SonarException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.server.platform.DefaultServerFileSystem;
import org.sonar.updatecenter.common.Release;
import org.sonar.updatecenter.common.Version;
public class PluginDownloader implements Startable {
- private static final Logger LOG = LoggerFactory.getLogger(PluginDownloader.class);
+ private static final Logger LOG = Loggers.get(PluginDownloader.class);
private static final String TMP_SUFFIX = "tmp";
private static final String PLUGIN_EXTENSION = "jar";
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.Server;
import org.sonar.api.platform.ServerUpgradeStatus;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.plugins.DefaultPluginMetadata;
import org.sonar.server.platform.DefaultServerFileSystem;
import org.sonar.updatecenter.common.PluginReferential;
public class ServerPluginJarsInstaller {
- private static final Logger LOG = LoggerFactory.getLogger(ServerPluginJarsInstaller.class);
+ private static final Logger LOG = Loggers.get(ServerPluginJarsInstaller.class);
private final Server server;
private final DefaultServerFileSystem fs;
package org.sonar.server.plugins;
import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.Plugin;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
clazz = classloader.loadClass(classname);
} catch (ClassNotFoundException e) {
- LoggerFactory.getLogger(getClass()).warn("Class not found in plugin " + pluginKey + ": " + classname, e);
+ Loggers.get(getClass()).warn("Class not found in plugin " + pluginKey + ": " + classname, e);
}
}
return clazz;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.server.platform.Platform;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class StaticResourcesServlet extends HttpServlet {
- private static final Logger LOG = LoggerFactory.getLogger(StaticResourcesServlet.class);
+ private static final Logger LOG = Loggers.get(StaticResourcesServlet.class);
private static final long serialVersionUID = -2577454614650178426L;
@Override
import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
public UpdateCenterClient(UriReader uriReader, Settings settings) throws URISyntaxException {
this.uriReader = uriReader;
this.uri = new URI(settings.getString(URL_PROPERTY));
- LoggerFactory.getLogger(getClass()).info("Update center: " + uriReader.description(uri));
+ Loggers.get(getClass()).info("Update center: " + uriReader.description(uri));
}
public UpdateCenter getUpdateCenter() {
return new UpdateCenterDeserializer(Mode.PROD, true).fromProperties(properties);
} catch (Exception e) {
- LoggerFactory.getLogger(getClass()).error("Fail to connect to update center", e);
+ Loggers.get(getClass()).error("Fail to connect to update center", e);
return null;
} finally {
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.profiles.ProfileDefinition;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.ActiveRuleParam;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.api.utils.ValidationMessages;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.core.template.LoadedTemplateDto;
*/
public class RegisterQualityProfiles implements ServerComponent {
- private static final Logger LOGGER = LoggerFactory.getLogger(RegisterQualityProfiles.class);
+ private static final Logger LOGGER = Loggers.get(RegisterQualityProfiles.class);
private static final String DEFAULT_PROFILE_NAME = "Sonar way";
private final PersistentSettings settings;
import com.google.common.collect.Iterables;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.ValidationMessages;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.server.debt.DebtModelPluginRepository;
import org.sonar.server.debt.DebtModelXMLExporter;
*/
public class DeprecatedRulesDefinitionLoader implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(DeprecatedRulesDefinitionLoader.class);
+ private static final Logger LOG = Loggers.get(DeprecatedRulesDefinitionLoader.class);
private final RuleI18nManager i18n;
private final RuleRepository[] repositories;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
*/
public class RegisterRules implements Startable {
- private static final Logger LOG = LoggerFactory.getLogger(RegisterRules.class);
+ private static final Logger LOG = Loggers.get(RegisterRules.class);
private final RuleDefinitionsLoader defLoader;
private final RuleActivator ruleActivator;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
*/
public class ActiveRuleCompleter implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(ActiveRuleCompleter.class);
+ private static final Logger LOG = Loggers.get(ActiveRuleCompleter.class);
private final QProfileLoader loader;
private final Languages languages;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.count.CountRequestBuilder;
import org.elasticsearch.action.count.CountResponse;
-import org.elasticsearch.action.get.*;
+import org.elasticsearch.action.get.GetRequestBuilder;
+import org.elasticsearch.action.get.GetResponse;
+import org.elasticsearch.action.get.MultiGetItemResponse;
+import org.elasticsearch.action.get.MultiGetRequest;
+import org.elasticsearch.action.get.MultiGetRequestBuilder;
+import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequestBuilder;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.*;
+import org.elasticsearch.index.query.BoolFilterBuilder;
+import org.elasticsearch.index.query.FilterBuilder;
+import org.elasticsearch.index.query.FilterBuilders;
+import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount;
import org.elasticsearch.search.fetch.source.FetchSourceContext;
import org.joda.time.DateTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.Dto;
import org.sonar.server.exceptions.NotFoundException;
import javax.annotation.Nullable;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Queue;
public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serializable>
implements Index<DOMAIN, DTO, KEY> {
- private static final Logger LOG = LoggerFactory.getLogger(BaseIndex.class);
+ private static final Logger LOG = Loggers.get(BaseIndex.class);
private final SearchClient client;
private final BaseNormalizer<DTO, KEY> normalizer;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram;
import org.elasticsearch.search.aggregations.bucket.missing.Missing;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.util.ArrayList;
import java.util.Collection;
class Facets {
- private static final Logger LOGGER = LoggerFactory.getLogger(Facets.class);
+ private static final Logger LOGGER = Loggers.get(Facets.class);
private final Multimap<String, FacetValue> facetValues;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.cluster.WorkQueue;
import org.sonar.server.search.action.IndexAction;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
private final SearchClient searchClient;
private final ComponentContainer container;
- private static final Logger LOGGER = LoggerFactory.getLogger(IndexQueue.class);
+ private static final Logger LOGGER = Loggers.get(IndexQueue.class);
private static final Integer CONCURRENT_NORMALIZATION_FACTOR = 1;
*/
package org.sonar.server.search;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.DbSession;
import org.sonar.server.activity.index.ActivityIndex;
import org.sonar.server.db.Dao;
public class IndexSynchronizer {
- private static final Logger LOG = LoggerFactory.getLogger(IndexSynchronizer.class);
+ private static final Logger LOG = Loggers.get(IndexSynchronizer.class);
private final DbClient db;
private final IndexClient index;
package org.sonar.server.source;
import com.google.common.io.Closeables;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.Nullable;
} catch (IOException exception) {
String errorMsg = "An exception occurred while highlighting the syntax of one of the project's files";
- LoggerFactory.getLogger(HtmlTextDecorator.class).error(errorMsg);
+ Loggers.get(HtmlTextDecorator.class).error(errorMsg);
throw new IllegalStateException(errorMsg, exception);
} finally {
Closeables.closeQuietly(stringBuffer);
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import org.apache.commons.lang.builder.EqualsBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerComponent;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.utils.Duration;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.rule.RuleDto;
*/
public class CopyRequirementsFromCharacteristicsToRules implements ServerComponent {
- private static final Logger LOGGER = LoggerFactory.getLogger(CopyRequirementsFromCharacteristicsToRules.class);
+ private static final Logger LOGGER = Loggers.get(CopyRequirementsFromCharacteristicsToRules.class);
private static final String TEMPLATE_KEY = "CopyRequirementsFromCharacteristicsToRules";
package org.sonar.server.startup;
import com.google.common.annotations.VisibleForTesting;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.properties.PropertyDto;
}
public void start() {
- logServerId(LoggerFactory.getLogger(LogServerId.class));
+ logServerId(Loggers.get(LogServerId.class));
}
@VisibleForTesting
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.Dashboard;
import org.sonar.api.web.DashboardTemplate;
import org.sonar.core.dashboard.ActiveDashboardDao;
* @since 2.13
*/
public class RegisterDashboards implements Startable {
- private static final Logger LOG = LoggerFactory.getLogger(RegisterDashboards.class);
+ private static final Logger LOG = Loggers.get(RegisterDashboards.class);
static final String DEFAULT_DASHBOARD_NAME = "Dashboard";
package org.sonar.server.startup;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.server.debt.DebtModelBackup;
public class RegisterDebtModel {
- private static final Logger LOGGER = LoggerFactory.getLogger(RegisterDebtModel.class);
+ private static final Logger LOGGER = Loggers.get(RegisterDebtModel.class);
private final CharacteristicDao dao;
private final DebtModelBackup debtModelBackup;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.qualitygate.db.QualityGateConditionDao;
import org.sonar.jpa.dao.MeasuresDao;
public class RegisterMetrics {
- private static final Logger LOG = LoggerFactory.getLogger(RegisterMetrics.class);
+ private static final Logger LOG = Loggers.get(RegisterMetrics.class);
private final MeasuresDao measuresDao;
private final Metrics[] metricsRepositories;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.Criterion;
import org.sonar.api.web.Filter;
import org.sonar.api.web.FilterColumn;
* @since 3.1
*/
public final class RegisterNewMeasureFilters {
- private static final Logger LOG = LoggerFactory.getLogger(RegisterNewMeasureFilters.class);
+ private static final Logger LOG = Loggers.get(RegisterNewMeasureFilters.class);
private final List<FilterTemplate> filterTemplates;
private final MeasureFilterDao filterDao;
package org.sonar.server.startup;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.PermissionTemplateDao;
import org.sonar.core.permission.PermissionTemplateDto;
public static final String DEFAULT_TEMPLATE_PROPERTY = "sonar.permission.template.default";
public static final String DEFAULT_PROJECTS_TEMPLATE_PROPERTY = "sonar.permission.template.TRK.default";
- private static final Logger LOG = LoggerFactory.getLogger(RegisterPermissionTemplates.class);
+ private static final Logger LOG = Loggers.get(RegisterPermissionTemplates.class);
private final LoadedTemplateDao loadedTemplateDao;
private final PermissionTemplateDao permissionTemplateDao;
package org.sonar.server.startup;
import com.google.common.base.Strings;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.core.properties.PropertiesDao;
}
public void start() {
- LoggerFactory.getLogger(RenameDeprecatedPropertyKeys.class).info("Rename deprecated property keys");
+ Loggers.get(RenameDeprecatedPropertyKeys.class).info("Rename deprecated property keys");
for (PropertyDefinition definition : definitions.getAll()) {
if (!Strings.isNullOrEmpty(definition.deprecatedKey())) {
dao.renamePropertyKey(definition.deprecatedKey(), definition.key());
import com.google.common.collect.ImmutableMap;
import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.CoreProperties;
import org.sonar.api.platform.Server;
import org.sonar.server.platform.PersistentSettings;
@Override
public void start() {
- LoggerFactory.getLogger(getClass()).debug("Persisting server metadata");
+ Loggers.get(getClass()).debug("Persisting server metadata");
persistentSettings.saveProperties(ImmutableMap.of(
CoreProperties.SERVER_ID, server.getId(),
CoreProperties.SERVER_VERSION, server.getVersion(),
*/
package org.sonar.server.ui;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.config.License;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
try {
return get(Class.forName(className));
} catch (ClassNotFoundException e) {
- LoggerFactory.getLogger(getClass()).error("Component not found: " + className, e);
+ Loggers.get(getClass()).error("Component not found: " + className, e);
return null;
}
}
try {
get(ComponentCleanerService.class).delete(projectKey);
} catch (RuntimeException e) {
- LoggerFactory.getLogger(JRubyFacade.class).error("Fail to delete resource with key: " + projectKey, e);
+ Loggers.get(JRubyFacade.class).error("Fail to delete resource with key: " + projectKey, e);
throw e;
}
}
public void logError(String message) {
- LoggerFactory.getLogger(getClass()).error(message);
+ Loggers.get(getClass()).error(message);
}
public boolean hasSecretKey() {
package org.sonar.server.ui;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.profiling.Profiling;
import org.sonar.core.profiling.Profiling.Level;
import org.sonar.core.profiling.StopWatch;
*/
public class JRubyProfiling {
- private static final Logger LOG = LoggerFactory.getLogger(JRubyProfiling.class);
+ private static final Logger LOG = Loggers.get(JRubyProfiling.class);
private Profiling profiling;
*/
package org.sonar.server.user;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.ServerComponent;
import org.sonar.api.platform.NewUserHandler;
}
public void onNewUser(NewUserHandler.Context context) {
- LoggerFactory.getLogger(NewUserNotifier.class).debug("User created: " + context.getLogin() + ". Notifying " + NewUserHandler.class.getSimpleName() + " handlers...");
+ Loggers.get(NewUserNotifier.class).debug("User created: " + context.getLogin() + ". Notifying " + NewUserHandler.class.getSimpleName() + " handlers...");
for (NewUserHandler handler : handlers) {
handler.doOnNewUser(context);
}
import org.apache.commons.lang.StringUtils;
import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.ServerComponent;
import org.sonar.api.config.Settings;
import org.sonar.api.security.LoginPasswordAuthenticator;
import org.sonar.api.security.SecurityRealm;
import org.sonar.api.utils.SonarException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
/**
* @since 2.14
@Override
public void start() {
if (realm != null) {
- Logger logger = LoggerFactory.getLogger("org.sonar.INFO");
+ Logger logger = Loggers.get("org.sonar.INFO");
try {
logger.info("Security realm: " + realm.getName());
realm.init();
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.HashMultimap;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.security.DefaultGroups;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
public static final UserSession ANONYMOUS = new UserSession();
private static final ThreadLocal<UserSession> THREAD_LOCAL = new ThreadLocal<UserSession>();
- private static final Logger LOG = LoggerFactory.getLogger(UserSession.class);
+ private static final Logger LOG = Loggers.get(UserSession.class);
private static final String INSUFFICIENT_PRIVILEGES_MESSAGE = "Insufficient privileges";
private Integer userId;
*/
package org.sonar.server.util;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.util.Timer;
import java.util.TimerTask;
public static ProgressLogger create(Class clazz, AtomicLong counter) {
String threadName = String.format("ProgressLogger[%s]", clazz.getSimpleName());
- Logger logger = LoggerFactory.getLogger(clazz);
+ Logger logger = Loggers.get(clazz);
return new ProgressLogger(threadName, counter, logger);
}
import com.google.common.base.Charsets;
import org.picocontainer.Startable;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.ServerComponent;
import org.sonar.api.i18n.I18n;
import org.sonar.api.server.ws.Request;
} catch (ServerException e) {
sendErrors(response, e.httpCode(), new Errors().add(Message.of(e.getMessage())));
} catch (Exception e) {
- LoggerFactory.getLogger(getClass()).error("Fail to process request " + request, e);
+ // TODO implement Request.toString()
+ Loggers.get(getClass()).error("Fail to process request " + request, e);
sendErrors(response, 500, new Errors().add(Message.of(e.getMessage())));
}
}
import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.Logger;
import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.purge.IdUuidPair;
import org.apache.coyote.http11.AbstractHttp11JsseProtocol;
import org.junit.Test;
import org.mockito.Mockito;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import org.sonar.process.Props;
import java.util.Properties;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import org.sonar.process.ProcessConstants;
import org.sonar.process.Props;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
-import org.slf4j.Logger;
import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.Logger;
import org.sonar.server.es.EsTester;
import org.sonar.server.user.index.UserIndex;
import org.sonar.server.user.index.UserIndexDefinition;
package org.sonar.server.db.migrations;
import org.junit.Test;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import java.sql.SQLException;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
public class ProgressTest {
@Test
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform;
-
-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.joran.spi.JoranException;
-import ch.qos.logback.core.read.ListAppender;
-import ch.qos.logback.core.status.Status;
-import ch.qos.logback.core.util.StatusPrinter;
-import org.junit.Test;
-import org.sonar.server.computation.ComputationThreadLauncher;
-
-import java.net.URL;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class SwitchLogbackAppenderTest {
-
- LoggerContext loggerContext = new LoggerContext();
- Logger logger = loggerContext.getLogger(this.getClass().getName());
- SwitchLogbackAppender switchAppender;
- ListAppender<ILoggingEvent> console, analyisReports;
-
- protected void configure(URL file) throws JoranException {
- JoranConfigurator jc = new JoranConfigurator();
- jc.setContext(loggerContext);
- jc.doConfigure(file);
-
- Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
- switchAppender = (SwitchLogbackAppender) root.getAppender("SWITCH");
- console = (ListAppender<ILoggingEvent>) switchAppender.getAppender("CONSOLE");
- analyisReports = (ListAppender<ILoggingEvent>) switchAppender.getAppender("ANALYSIS_REPORTS");
- }
-
- /**
- * Standard log goes to console only
- */
- @Test
- public void standard_log() throws JoranException {
- configure(getClass().getResource("SwitchLogbackAppenderTest/valid-switch.xml"));
-
- logger.info("hello");
-
- assertThat(console.list).hasSize(1);
- assertThat(console.list.get(0).getMessage()).isEqualTo("hello");
- assertThat(analyisReports.list).isEmpty();
- }
-
- /**
- * Compute service log goes to dedicated appender. Warnings and errors are logged in both appenders.
- */
- @Test
- public void compute_service_log_goes_to_dedicated_appender() throws JoranException {
- configure(getClass().getResource("SwitchLogbackAppenderTest/valid-switch.xml"));
-
- String initialThreadName = Thread.currentThread().getName();
- Thread.currentThread().setName(ComputationThreadLauncher.THREAD_NAME_PREFIX + "test");
- try {
- logger.info("hello");
- assertThat(analyisReports.list).hasSize(1);
- assertThat(analyisReports.list.get(0).getMessage()).isEqualTo("hello");
- assertThat(console.list).isEmpty();
-
- logger.warn("a warning");
- assertThat(analyisReports.list).hasSize(2);
- assertThat(analyisReports.list.get(1).getMessage()).isEqualTo("a warning");
- assertThat(console.list).hasSize(1);
- assertThat(console.list.get(0).getMessage()).isEqualTo("a warning");
-
- logger.error("an error");
- assertThat(analyisReports.list).hasSize(3);
- assertThat(analyisReports.list.get(2).getMessage()).isEqualTo("an error");
- assertThat(console.list).hasSize(2);
- assertThat(console.list.get(1).getMessage()).isEqualTo("an error");
-
- } finally {
- Thread.currentThread().setName(initialThreadName);
- }
- }
-
- @Test
- public void fail_if_bad_configuration() throws JoranException {
- boolean foundError = false;
- configure(getClass().getResource("SwitchLogbackAppenderTest/invalid-switch.xml"));
- StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
- for (Status status : loggerContext.getStatusManager().getCopyOfStatusList()) {
- Throwable error = status.getThrowable();
- if (error != null) {
- assertThat(error).hasMessage("Invalid appender name: UNKNOWN");
- foundError = true;
- }
- }
- assertThat(foundError).isTrue();
- }
-
- @Test
- public void test_logback_internals() throws Exception {
- configure(getClass().getResource("SwitchLogbackAppenderTest/valid-switch.xml"));
-
- assertThat(switchAppender.iteratorForAppenders()).hasSize(2);
- assertThat(switchAppender.isAttached(console)).isTrue();
-
- assertThat(switchAppender.detachAppender("CONSOLE")).isTrue();
- assertThat(switchAppender.detachAppender(analyisReports)).isTrue();
- switchAppender.detachAndStopAllAppenders();
- }
-}
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.slf4j.Logger;
import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.log.Logger;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.properties.PropertyDto;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.rules.ExternalResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.resources.Language;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.process.ProcessConstants;
import org.sonar.server.es.EsServerHolder;
import org.sonar.server.platform.BackendCleanup;
*/
public class ServerTester extends ExternalResource {
- private static final Logger LOG = LoggerFactory.getLogger(ServerTester.class);
+ private static final Logger LOG = Loggers.get(ServerTester.class);
private static final String PROP_PREFIX = "mediumTests.";
private Platform platform;
package org.sonar.server.util;
import org.junit.Test;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import java.util.concurrent.atomic.AtomicLong;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
public class ProgressLoggerTest {
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<configuration debug="false">
- <appender name="CONSOLE" class="ch.qos.logback.core.read.ListAppender" />
- <appender name="UNKNOWN" class="ch.qos.logback.core.read.ListAppender" />
-
- <appender name="SWITCH" class="org.sonar.server.platform.SwitchLogbackAppender">
- <appender-ref ref="CONSOLE" />
- <appender-ref ref="UNKNOWN" />
- </appender>
-
- <root level="DEBUG">
- <appender-ref ref="SWITCH" />
- </root>
-</configuration>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<configuration debug="false">
- <appender name="CONSOLE" class="ch.qos.logback.core.read.ListAppender" />
- <appender name="ANALYSIS_REPORTS" class="ch.qos.logback.core.read.ListAppender" />
-
- <appender name="SWITCH" class="org.sonar.server.platform.SwitchLogbackAppender">
- <!-- do not change appender names. See org.sonar.server.platform.SwitchLogbackAppender -->
- <appender-ref ref="CONSOLE" />
- <appender-ref ref="ANALYSIS_REPORTS" />
- </appender>
-
- <root level="DEBUG">
- <appender-ref ref="SWITCH" />
- </root>
-</configuration>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</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>org.slf4j</groupId>
+ <artifactId>jul-to-slf4j</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.picocontainer.injectors.ProviderAdapter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.debt.DebtCharacteristic;
import org.sonar.api.batch.debt.DebtModel;
import org.sonar.api.batch.debt.internal.DefaultDebtCharacteristic;
import org.sonar.api.batch.debt.internal.DefaultDebtModel;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
public class DebtModelProvider extends ProviderAdapter {
- private static final Logger LOG = LoggerFactory.getLogger(DebtModelProvider.class);
+ private static final Logger LOG = Loggers.get(DebtModelProvider.class);
private DebtModel model;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import org.picocontainer.injectors.ProviderAdapter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.debt.DebtCharacteristic;
import org.sonar.api.batch.debt.DebtModel;
import org.sonar.api.batch.debt.DebtRemediationFunction;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.Durations;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.rule.RuleDao;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
*/
public class RulesProvider extends ProviderAdapter {
- private static final Logger LOG = LoggerFactory.getLogger(RulesProvider.class);
+ private static final Logger LOG = Loggers.get(RulesProvider.class);
private Rules singleton = null;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterators;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.bootstrap.ServerClient;
public class LastLineHashes implements BatchComponent {
- private static final Logger LOG = LoggerFactory.getLogger(LastLineHashes.class);
+ private static final Logger LOG = Loggers.get(LastLineHashes.class);
private final ServerClient server;
package org.sonar.core.computation.dbcleaner;
import com.google.common.annotations.VisibleForTesting;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.TimeUtils;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
-import org.sonar.core.purge.*;
+import org.sonar.core.purge.IdUuidPair;
+import org.sonar.core.purge.PurgeConfiguration;
+import org.sonar.core.purge.PurgeDao;
+import org.sonar.core.purge.PurgeListener;
+import org.sonar.core.purge.PurgeProfiler;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.plugins.dbcleaner.api.PurgeTask;
* @since 2.14
*/
public class DefaultPurgeTask implements PurgeTask {
- private static final Logger LOG = LoggerFactory.getLogger(DefaultPurgeTask.class);
+ private static final Logger LOG = Loggers.get(DefaultPurgeTask.class);
private final PurgeProfiler profiler;
private final PurgeDao purgeDao;
private final ResourceDao resourceDao;
package org.sonar.core.purge;
import com.google.common.annotations.VisibleForTesting;
-import org.slf4j.Logger;
import org.sonar.api.utils.TimeUtils;
+import org.sonar.api.utils.log.Logger;
import java.util.ArrayList;
import java.util.Collections;
package org.sonar.core.computation.dbcleaner;
-import ch.qos.logback.classic.Logger;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
+import org.sonar.api.utils.log.Logger;
import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
-import org.sonar.core.purge.*;
+import org.sonar.core.purge.IdUuidPair;
+import org.sonar.core.purge.PurgeConfiguration;
+import org.sonar.core.purge.PurgeDao;
+import org.sonar.core.purge.PurgeListener;
+import org.sonar.core.purge.PurgeProfiler;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import static org.mockito.Matchers.contains;
import static org.mockito.Mockito.mock;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.PropertyType;
import org.sonar.api.ServerComponent;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.api.utils.FieldUtils2;
import org.sonar.api.utils.SonarException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.lang.reflect.Field;
import java.util.Collection;
@Deprecated
public final class AnnotationRuleParser implements ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(AnnotationRuleParser.class);
+ private static final Logger LOG = Loggers.get(AnnotationRuleParser.class);
public List<Rule> parse(String repositoryKey, Collection<Class> annotatedClasses) {
List<Rule> rules = Lists.newArrayList();
public class DuplicationsTestUtil {
- private static final File fileDir = new File("src/test/files/");
-
public static File findFile(String relativePathToFile) {
- return new File(fileDir, relativePathToFile);
+ File file = new File("src/test/files/", relativePathToFile);
+ if (!file.exists()) {
+ // IntellijIDEA resolves path from root module basedir
+ file = new File("sonar-duplications/src/test/files/", relativePathToFile);
+ }
+ return file;
}
}
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-colorizer</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-duplications</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-squid</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<!-- TODO we can't remove hibernate-annotations, because currently it's used
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
+ <scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<version>3.0.1</version>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <optional>true</optional>
+ </dependency>
<!-- unit tests -->
<dependency>
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.project.MavenProject;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Loggers;
import java.nio.charset.Charset;
import java.util.Collection;
return Charset.forName(encoding);
} catch (Exception e) {
- LoggerFactory.getLogger(MavenUtils.class).warn("Can not get project charset", e);
+ Loggers.get(MavenUtils.class).warn("Can not get project charset", e);
}
}
return Charset.defaultCharset();
package org.sonar.api.platform;
import com.google.common.annotations.VisibleForTesting;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.utils.internal.Uuids;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.util.HashSet;
import java.util.Set;
private final Set<Class> objectsWithoutToString = new HashSet<Class>();
Object of(Object component) {
- return of(component, LoggerFactory.getLogger(ComponentKeys.class));
+ return of(component, Loggers.get(ComponentKeys.class));
}
@VisibleForTesting
import com.google.common.collect.Maps;
import org.apache.commons.lang.ArrayUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import java.util.ArrayList;
import java.util.Arrays;
*/
public class Languages implements BatchComponent, ServerComponent {
- private static final Logger LOG = LoggerFactory.getLogger(Languages.class);
+ private static final Logger LOG = Loggers.get(Languages.class);
private final Map<String, Language> map = Maps.newLinkedHashMap();
package org.sonar.api.rules;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.slf4j.LoggerFactory;
import org.sonar.api.resources.Resource;
+import org.sonar.api.utils.log.Loggers;
import java.util.Date;
public Violation setLineId(Integer lineId) {
if (lineId != null && lineId < 1) {
// TODO this normalization was added in 2.8, throw exception in future versions - see http://jira.codehaus.org/browse/SONAR-2386
- LoggerFactory.getLogger(getClass()).warn("line must not be less than 1 - in future versions this will cause IllegalArgumentException");
+ Loggers.get(getClass()).warn("line must not be less than 1 - in future versions this will cause IllegalArgumentException");
this.lineId = null;
} else {
this.lineId = lineId;
import com.google.common.collect.*;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerExtension;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.debt.DebtRemediationFunction;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
// Should fail in a perfect world, but at the time being the Findbugs plugin
// defines several times the rule EC_INCOMPATIBLE_ARRAY_COMPARE
// See http://jira.codehaus.org/browse/SONARJAVA-428
- LoggerFactory.getLogger(getClass()).warn(String.format("The rule '%s' of repository '%s' is declared several times", ruleKey, key));
+ Loggers.get(getClass()).warn(String.format("The rule '%s' of repository '%s' is declared several times", ruleKey, key));
}
NewRule newRule = new NewRule(key, ruleKey);
newRules.put(ruleKey, newRule);
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.api.utils.FieldUtils2;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.check.Cardinality;
import javax.annotation.CheckForNull;
+
import java.lang.reflect.Field;
import java.util.List;
*/
public class RulesDefinitionAnnotationLoader {
- private static final Logger LOG = LoggerFactory.getLogger(RulesDefinitionAnnotationLoader.class);
+ private static final Logger LOG = Loggers.get(RulesDefinitionAnnotationLoader.class);
private static final Function<Class<?>, RuleParamType> TYPE_FOR_CLASS = Functions.forMap(
ImmutableMap.<Class<?>, RuleParamType>builder()
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
private String readParamOrDefaultValue(String key, @Nullable WebService.Param definition) {
if (definition == null) {
String message = String.format("BUG - parameter '%s' is undefined for action '%s'", key, action.key());
- LoggerFactory.getLogger(getClass()).error(message);
+ Loggers.get(getClass()).error(message);
throw new IllegalArgumentException(message);
}
String deprecatedKey = definition.deprecatedKey();
import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.Nullable;
@Override
public InputStream getInput() throws IOException {
- LoggerFactory.getLogger(getClass()).debug("Download: " + uri + " (" + getProxySynthesis(uri, ProxySelector.getDefault()) + ")");
+ Loggers.get(getClass()).debug("Download: " + uri + " (" + getProxySynthesis(uri, ProxySelector.getDefault()) + ")");
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
connection.setRequestMethod(requestMethod);
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.*;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.Set;
public class LocalizedMessages extends ResourceBundle {
- private static final Logger LOG = LoggerFactory.getLogger(LocalizedMessages.class);
+ private static final Logger LOG = Loggers.get(LocalizedMessages.class);
private Locale locale;
private List<ResourceBundle> bundles;
*/
package org.sonar.api.utils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
/**
* A very simple profiler to log the time elapsed performing some tasks.
this.logger = logger;
}
+ /**
+ * @deprecated do not use SLF4J but org.sonar.api.utils.log.Logger
+ * @since 5.1
+ */
+ @Deprecated
+ public TimeProfiler(org.slf4j.Logger logger) {
+ this.logger = Loggers.get(logger.getName());
+ }
+
public TimeProfiler(Class clazz) {
- this.logger = LoggerFactory.getLogger(clazz);
+ this.logger = Loggers.get(clazz);
}
/**
* Use the default Sonar logger
*/
public TimeProfiler() {
- this.logger = LoggerFactory.getLogger(getClass());
+ this.logger = Loggers.get(getClass());
}
public TimeProfiler start(String name) {
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
bf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
bf.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
} catch (ParserConfigurationException e) {
- Logger log = LoggerFactory.getLogger(this.getClass().getName());
+ Logger log = Loggers.get(this.getClass().getName());
log.error("Error occured during features set up.", e);
}
try {
import com.google.common.base.Charsets;
import com.google.common.io.Closeables;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import javax.annotation.Nullable;
*/
public class CommandExecutor {
- private static final Logger LOG = LoggerFactory.getLogger(CommandExecutor.class);
+ private static final Logger LOG = Loggers.get(CommandExecutor.class);
private static final CommandExecutor INSTANCE = new CommandExecutor();
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import javax.annotation.Nullable;
+
+abstract class BaseLogger implements Logger {
+ @Override
+ public void debug(String msg) {
+ LogInterceptor.instance.log(msg);
+ doDebug(msg);
+ }
+
+ @Override
+ public void debug(String pattern, @Nullable Object arg) {
+ LogInterceptor.instance.log(pattern, arg);
+ doDebug(pattern, arg);
+ }
+
+ @Override
+ public void debug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ LogInterceptor.instance.log(msg, arg1, arg2);
+ doDebug(msg, arg1, arg2);
+ }
+
+ @Override
+ public void debug(String msg, Object... args) {
+ LogInterceptor.instance.log(msg, args);
+ doDebug(msg, args);
+ }
+
+ @Override
+ public void info(String msg) {
+ LogInterceptor.instance.log(msg);
+ doInfo(msg);
+ }
+
+ @Override
+ public void info(String msg, @Nullable Object arg) {
+ LogInterceptor.instance.log(msg, arg);
+ doInfo(msg, arg);
+ }
+
+ @Override
+ public void info(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ LogInterceptor.instance.log(msg, arg1, arg2);
+ doInfo(msg, arg1, arg2);
+ }
+
+ @Override
+ public void info(String msg, Object... args) {
+ LogInterceptor.instance.log(msg, args);
+ doInfo(msg, args);
+ }
+
+ @Override
+ public void warn(String msg) {
+ LogInterceptor.instance.log(msg);
+ doWarn(msg);
+ }
+
+ @Override
+ public void warn(String msg, @Nullable Object arg) {
+ LogInterceptor.instance.log(msg, arg);
+ doWarn(msg, arg);
+ }
+
+ @Override
+ public void warn(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ LogInterceptor.instance.log(msg, arg1, arg2);
+ doWarn(msg, arg1, arg2);
+ }
+
+ @Override
+ public void warn(String msg, Object... args) {
+ LogInterceptor.instance.log(msg, args);
+ doWarn(msg, args);
+ }
+
+ @Override
+ public void error(String msg) {
+ LogInterceptor.instance.log(msg);
+ doError(msg);
+ }
+
+ @Override
+ public void error(String msg, @Nullable Object arg) {
+ LogInterceptor.instance.log(msg, arg);
+ doError(msg, arg);
+ }
+
+ @Override
+ public void error(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ LogInterceptor.instance.log(msg, arg1, arg2);
+ doError(msg, arg1, arg2);
+ }
+
+ @Override
+ public void error(String msg, Object... args) {
+ LogInterceptor.instance.log(msg, args);
+ doError(msg, args);
+ }
+
+ @Override
+ public void error(String msg, Throwable thrown) {
+ LogInterceptor.instance.log(msg, thrown);
+ doError(msg, thrown);
+ }
+
+ abstract void doDebug(String msg);
+
+ abstract void doDebug(String msg, @Nullable Object arg);
+
+ abstract void doDebug(String msg, @Nullable Object arg1, @Nullable Object arg2);
+
+ abstract void doDebug(String msg, Object... args);
+
+ /**
+ * Logs an INFO level message.
+ */
+ abstract void doInfo(String msg);
+
+ abstract void doInfo(String msg, @Nullable Object arg);
+
+ abstract void doInfo(String msg, @Nullable Object arg1, @Nullable Object arg2);
+
+ abstract void doInfo(String msg, Object... args);
+
+ /**
+ * Logs a WARN level message.
+ */
+ abstract void doWarn(String msg);
+
+ abstract void doWarn(String msg, @Nullable Object arg);
+
+ abstract void doWarn(String msg, @Nullable Object arg1, @Nullable Object arg2);
+
+ abstract void doWarn(String msg, Object... args);
+
+ /**
+ * Logs an ERROR level message.
+ */
+ abstract void doError(String msg);
+
+ abstract void doError(String msg, @Nullable Object arg);
+
+ abstract void doError(String msg, @Nullable Object arg1, @Nullable Object arg2);
+
+ abstract void doError(String msg, Object... args);
+
+ abstract void doError(String msg, Throwable thrown);
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Objects;
+
+class ConsoleFormatter {
+
+ private ConsoleFormatter() {
+ // only static methods
+ }
+
+ static String format(String pattern, Object... args) {
+ String result = pattern;
+ for (Object arg : args) {
+ result = StringUtils.replaceOnce(result, "{}", Objects.toString(arg));
+ }
+ return result;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import javax.annotation.Nullable;
+
+import java.io.PrintStream;
+
+import static org.sonar.api.utils.log.ConsoleFormatter.format;
+
+/**
+ * Slow implementation based on {@link java.lang.System#out}. It is not production-ready and it must be used
+ * only for the tests that do not have logback dependency.
+ * <p/>Implementation of message patterns is naive. It does not support escaped '{' and '}'
+ * arguments.
+ */
+class ConsoleLogger extends BaseLogger {
+
+ private final PrintStream stream;
+
+ ConsoleLogger(String unusedName) {
+ this.stream = System.out;
+ }
+
+ ConsoleLogger(PrintStream stream) {
+ this.stream = stream;
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return Loggers.getFactory().isDebugEnabled();
+ }
+
+ @Override
+ protected void doDebug(String msg) {
+ if (isDebugEnabled()) {
+ log("DEBUG", msg);
+ }
+ }
+
+ @Override
+ protected void doDebug(String pattern, @Nullable Object arg) {
+ if (isDebugEnabled()) {
+ debug(format(pattern, arg));
+ }
+ }
+
+ @Override
+ protected void doDebug(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
+ if (isDebugEnabled()) {
+ debug(format(pattern, arg1, arg2));
+ }
+ }
+
+ @Override
+ protected void doDebug(String pattern, Object... args) {
+ if (isDebugEnabled()) {
+ debug(format(pattern, args));
+ }
+ }
+
+ @Override
+ protected void doInfo(String msg) {
+ log("INFO ", msg);
+ }
+
+ @Override
+ protected void doInfo(String pattern, @Nullable Object arg) {
+ info(format(pattern, arg));
+ }
+
+ @Override
+ protected void doInfo(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
+ info(format(pattern, arg1, arg2));
+ }
+
+ @Override
+ protected void doInfo(String pattern, Object... args) {
+ info(format(pattern, args));
+ }
+
+ @Override
+ protected void doWarn(String msg) {
+ log("WARN ", msg);
+ }
+
+ @Override
+ protected void doWarn(String pattern, @Nullable Object arg) {
+ warn(format(pattern, arg));
+ }
+
+ @Override
+ protected void doWarn(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
+ warn(format(pattern, arg1, arg2));
+ }
+
+ @Override
+ protected void doWarn(String pattern, Object... args) {
+ warn(format(pattern, args));
+ }
+
+ @Override
+ protected void doError(String msg) {
+ log("ERROR", msg);
+ }
+
+ @Override
+ protected void doError(String pattern, @Nullable Object arg) {
+ error(format(pattern, arg));
+ }
+
+ @Override
+ protected void doError(String pattern, @Nullable Object arg1, @Nullable Object arg2) {
+ error(format(pattern, arg1, arg2));
+ }
+
+ @Override
+ protected void doError(String pattern, Object... args) {
+ error(format(pattern, args));
+ }
+
+ @Override
+ public void doError(String msg, Throwable thrown) {
+ doError(msg);
+ thrown.printStackTrace();
+ }
+
+ private void log(String level, String msg) {
+ this.stream.println(String.format("%s %s", level, msg));
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+class ConsoleLoggers extends Loggers {
+
+ private boolean debugEnabled = false;
+
+ @Override
+ protected Logger newInstance(String name) {
+ return new ConsoleLogger(name);
+ }
+
+ @Override
+ protected boolean isDebugEnabled() {
+ return debugEnabled;
+ }
+
+ @Override
+ protected void enableDebug(boolean b) {
+ this.debugEnabled = b;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class ListInterceptor extends LogInterceptor {
+
+ private final List<String> logs = new ArrayList<>();
+
+ @Override
+ public void log(String msg) {
+ logs.add(msg);
+ }
+
+ @Override
+ public void log(String msg, Object arg) {
+ logs.add(ConsoleFormatter.format(msg, arg));
+ }
+
+ @Override
+ public void log(String msg, Object arg1, Object arg2) {
+ logs.add(ConsoleFormatter.format(msg, arg1, arg2));
+ }
+
+ @Override
+ public void log(String msg, Object... args) {
+ logs.add(ConsoleFormatter.format(msg, args));
+ }
+
+ @Override
+ public void log(String msg, Throwable thrown) {
+ logs.add(msg);
+ }
+
+ public List<String> logs() {
+ return logs;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+abstract class LogInterceptor {
+
+ static LogInterceptor instance = NullInterceptor.NULL_INSTANCE;
+
+ abstract void log(String msg);
+
+ abstract void log(String msg, Object arg);
+
+ abstract void log(String msg, Object arg1, Object arg2);
+
+ abstract void log(String msg, Object... args);
+
+ abstract void log(String msg, Throwable thrown);
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.rules.ExternalResource;
+
+import java.util.List;
+
+/**
+ * <b>For tests only</b>
+ * <p/>
+ * This JUnit rule allows to configure and access logs in tests. By default
+ * debug logs are enabled.
+ * <p/>
+ * Warning - not compatible with parallel execution of tests.
+ * <p/>
+ * Example:
+ * <pre>
+ * public class MyClass {
+ * private final Logger logger = Loggers.get("logger_name");
+ *
+ * public void doSomething() {
+ * logger.info("foo");
+ * }
+ * }
+ *
+ * public class MyTest {
+ * @Rule
+ * public LogTester logTester = new LogTester();
+ *
+ * @Test
+ * public void test_log() {
+ * new MyClass().doSomething();
+ *
+ * assertThat(logTester.logs()).containsOnly("foo");
+ * }
+ * }
+ * </pre>
+ *
+ * @since 5.1
+ */
+public class LogTester extends ExternalResource {
+
+ private boolean initialDebugMode;
+
+ @Override
+ protected void before() throws Throwable {
+ initialDebugMode = Loggers.getFactory().isDebugEnabled();
+
+ // this shared instance breaks compatibility with parallel execution of tests
+ LogInterceptor.instance = new ListInterceptor();
+ enableDebug(true);
+ }
+
+ @Override
+ protected void after() {
+ enableDebug(initialDebugMode);
+ LogInterceptor.instance = NullInterceptor.NULL_INSTANCE;
+ }
+
+ /**
+ * @see #enableDebug(boolean)
+ */
+ public boolean isDebugEnabled() {
+ return Loggers.getFactory().isDebugEnabled();
+ }
+
+ /**
+ * Enable/disable debug logs. Info, warn and error logs are always enabled.
+ * By default debug logs are enabled when LogTester is started.
+ */
+ public LogTester enableDebug(boolean b) {
+ Loggers.getFactory().enableDebug(b);
+ return this;
+ }
+
+ /**
+ * Logs in chronological order (item at index 0 is the oldest one)
+ */
+ public List<String> logs() {
+ return ((ListInterceptor) LogInterceptor.instance).logs();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import javax.annotation.Nullable;
+
+/**
+ * Note that logback is accessed through SLF4J
+ */
+class LogbackLogger extends BaseLogger {
+
+ private final transient org.slf4j.Logger slf4j;
+
+ LogbackLogger(org.slf4j.Logger slf4j) {
+ this.slf4j = slf4j;
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return slf4j.isDebugEnabled();
+ }
+
+ @Override
+ protected void doDebug(String msg) {
+ slf4j.debug(msg);
+ }
+
+ @Override
+ protected void doDebug(String msg, @Nullable Object arg) {
+ slf4j.debug(msg, arg);
+ }
+
+ @Override
+ protected void doDebug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ slf4j.debug(msg, arg1, arg2);
+ }
+
+ @Override
+ protected void doDebug(String msg, Object... args) {
+ slf4j.debug(msg, args);
+ }
+
+ @Override
+ protected void doInfo(String msg) {
+ slf4j.info(msg);
+ }
+
+ @Override
+ protected void doInfo(String msg, @Nullable Object arg) {
+ slf4j.info(msg, arg);
+ }
+
+ @Override
+ protected void doInfo(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ slf4j.info(msg, arg1, arg2);
+ }
+
+ @Override
+ protected void doInfo(String msg, Object... args) {
+ slf4j.info(msg, args);
+ }
+
+ @Override
+ protected void doWarn(String msg) {
+ slf4j.warn(msg);
+ }
+
+ @Override
+ protected void doWarn(String msg, @Nullable Object arg) {
+ slf4j.warn(msg, arg);
+ }
+
+ @Override
+ protected void doWarn(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ slf4j.warn(msg, arg1, arg2);
+ }
+
+ @Override
+ protected void doWarn(String msg, Object... args) {
+ slf4j.warn(msg, args);
+ }
+
+ @Override
+ protected void doError(String msg) {
+ slf4j.error(msg);
+ }
+
+ @Override
+ protected void doError(String msg, @Nullable Object arg) {
+ slf4j.error(msg, arg);
+ }
+
+ @Override
+ protected void doError(String msg, @Nullable Object arg1, @Nullable Object arg2) {
+ slf4j.error(msg, arg1, arg2);
+ }
+
+ @Override
+ protected void doError(String msg, Object... args) {
+ slf4j.error(msg, args);
+ }
+
+ @Override
+ protected void doError(String msg, Throwable thrown) {
+ slf4j.error(msg, thrown);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import ch.qos.logback.classic.Level;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Note that this is not "Slf4jLoggers" as there's a coupling on Logback
+ * in order to change level of root logger.
+ */
+class LogbackLoggers extends Loggers {
+
+ @Override
+ protected Logger newInstance(String name) {
+ return new LogbackLogger(LoggerFactory.getLogger(name));
+ }
+
+ @Override
+ protected boolean isDebugEnabled() {
+ return LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).isDebugEnabled();
+ }
+
+ @Override
+ protected void enableDebug(boolean b) {
+ ch.qos.logback.classic.Logger logback = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
+ logback.setLevel(b ? Level.DEBUG : Level.INFO);
+ }
+}
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.sonar.api.utils.log;
+import javax.annotation.Nullable;
+
+/**
+ * SonarQube plugins are not coupled with external logging libraries like SLF4J or Logback.
+ *
+ * Example:
+ * <pre>
+ * public class MyClass {
+ * private final Logger logger = Loggers.get("logger_name");
+ *
+ * public void doSomething() {
+ * logger.info("something valuable for production environment");
+ * logger.warn("message with arguments {}Â and {}", "foo", 42);
+ * }
+ * }
+ * </pre>
+ *
+ * See {@link org.sonar.api.utils.log.LogTester} for testing facilities.
+ * @since 5.1
+ */
public interface Logger {
boolean isDebugEnabled();
- void debug(String message);
+ /**
+ * Logs a DEBUG level message. Debug messages must
+ * be valuable for production environments and are not for development debugging.
+ */
+ void debug(String msg);
+
+ void debug(String pattern, @Nullable Object arg);
+
+ void debug(String msg, @Nullable Object arg1, @Nullable Object arg2);
+
+ void debug(String msg, Object... args);
+
+ /**
+ * Logs an INFO level message.
+ */
+ void info(String msg);
+
+ void info(String msg, @Nullable Object arg);
+
+ void info(String msg, @Nullable Object arg1, @Nullable Object arg2);
+
+ void info(String msg, Object... args);
+
+ /**
+ * Logs a WARN level message.
+ */
+ void warn(String msg);
+
+ void warn(String msg, @Nullable Object arg);
+
+ void warn(String msg, @Nullable Object arg1, @Nullable Object arg2);
+
+ void warn(String msg, Object... args);
+
+ /**
+ * Logs an ERROR level message.
+ */
+ void error(String msg);
- void info(String message);
+ void error(String msg, @Nullable Object arg);
- void warn(String message);
+ void error(String msg, @Nullable Object arg1, @Nullable Object arg2);
- void error(String message);
+ void error(String msg, Object... args);
- void error(String message, Throwable throwable);
+ /**
+ * Logs an ERROR level message.
+ */
+ void error(String msg, Throwable thrown);
}
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
package org.sonar.api.utils.log;
-public class Loggers {
+/**
+ * @since 5.1
+ */
+public abstract class Loggers {
+ private static volatile Loggers factory;
+
+ static {
+ try {
+ Class.forName("org.slf4j.Logger");
+ factory = new LogbackLoggers();
+ } catch (Throwable e) {
+ // no slf4j -> testing environment
+ factory = new ConsoleLoggers();
+ }
+ }
+
+ public static Logger get(Class name) {
+ return factory.newInstance(name.getName());
+ }
+
+ public static Logger get(String name) {
+ return factory.newInstance(name);
+ }
+
+ static Loggers getFactory() {
+ return factory;
+ }
+
+ protected abstract Logger newInstance(String name);
+
+ protected abstract boolean isDebugEnabled();
+
+ protected abstract void enableDebug(boolean b);
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+/**
+ * Log interceptor that does nothing, so production-ready!
+ */
+class NullInterceptor extends LogInterceptor {
+
+ static final NullInterceptor NULL_INSTANCE = new NullInterceptor();
+
+ private NullInterceptor() {
+ }
+
+ @Override
+ void log(String msg) {
+ // nothing
+ }
+
+ @Override
+ void log(String msg, Object arg) {
+ // nothing
+ }
+
+ @Override
+ void log(String msg, Object arg1, Object arg2) {
+ // nothing
+ }
+
+ @Override
+ void log(String msg, Object... args) {
+ // nothing
+ }
+
+ @Override
+ void log(String msg, Throwable thrown) {
+ // nothing
+ }
+}
+++ /dev/null
-package org.sonar.api.utils.log.internal;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Lists;
-import org.sonar.api.utils.log.Logger;
-
-import java.util.List;
-
-/**
- * Implementation of {@link org.sonar.api.utils.log.Logger} which keeps logs
- * in memory, so that they can be loaded after writing. It is helpful
- * for testing.
- */
-public class InMemoryLogger implements Logger {
-
- private static enum Level {
- DEBUG, INFO, WARN, ERROR
- }
-
- private boolean debugEnabled = false;
- private final ArrayListMultimap<Level, String> logs = ArrayListMultimap.create();
-
- @Override
- public boolean isDebugEnabled() {
- return debugEnabled;
- }
-
- public InMemoryLogger setDebugEnabled(boolean b) {
- this.debugEnabled = b;
- return this;
- }
-
- @Override
- public void debug(String message) {
- if (isDebugEnabled()) {
- log(Level.DEBUG, message);
- }
- }
-
- @Override
- public void info(String message) {
- log(Level.INFO, message);
- }
-
- @Override
- public void warn(String message) {
- log(Level.WARN, message);
- }
-
- @Override
- public void error(String message) {
- log(Level.ERROR, message);
- }
-
- @Override
- public void error(String message, Throwable throwable) {
- log(Level.ERROR, String.format("%s | %s", message, throwable.getMessage()));
- }
-
- public List<String> logs() {
- return Lists.newArrayList(logs.values());
- }
-
- public List<String> debugLogs() {
- return logs.get(Level.DEBUG);
- }
-
- public List<String> infoLogs() {
- return logs.get(Level.INFO);
- }
-
- public List<String> warnLogs() {
- return logs.get(Level.WARN);
- }
-
- public List<String> errorLogs() {
- return logs.get(Level.ERROR);
- }
-
- public InMemoryLogger clear() {
- logs.clear();
- return this;
- }
-
- private void log(Level level, String message) {
- logs.put(level, message);
- }
-}
+++ /dev/null
-package org.sonar.api.utils.log.internal;
-
-
-import org.slf4j.LoggerFactory;
-import org.sonar.api.utils.log.Logger;
-
-public class Slf4jLoggers {
-
- public static class Slf4jLogger implements Logger {
- private final org.slf4j.Logger slf4j;
-
- public Slf4jLogger(org.slf4j.Logger slf4j) {
- this.slf4j = slf4j;
- }
-
- @Override
- public boolean isDebugEnabled() {
- return slf4j.isDebugEnabled();
- }
-
- @Override
- public void debug(String message) {
- slf4j.debug(message);
- }
-
- @Override
- public void info(String message) {
- slf4j.info(message);
- }
-
- @Override
- public void warn(String message) {
- slf4j.warn(message);
- }
-
- @Override
- public void error(String message) {
- slf4j.error(message);
- }
-
- @Override
- public void error(String message, Throwable throwable) {
- slf4j.error(message, throwable);
- }
- }
-
- public Slf4jLogger getLogger(String name) {
- return new Slf4jLogger(LoggerFactory.getLogger(name));
- }
-
- public Slf4jLogger getLogger(Class name) {
- return new Slf4jLogger(LoggerFactory.getLogger(name));
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.api.utils.log;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
package org.sonar.api.platform;
import org.junit.Test;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.startsWith;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.*;
public class ComponentKeysTest {
import org.junit.Before;
import org.junit.Test;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
package org.sonar.api.utils;
import org.junit.Test;
-import org.slf4j.Logger;
+import org.sonar.api.utils.log.Logger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
public class ValidationMessagesTest {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.Test;
+import org.sonar.test.TestUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ConsoleFormatterTest {
+
+ @Test
+ public void format() throws Exception {
+ assertThat(ConsoleFormatter.format("foo")).isEqualTo("foo");
+ assertThat(ConsoleFormatter.format("arg: {}", "foo")).isEqualTo("arg: foo");
+ assertThat(ConsoleFormatter.format("two args: {} and {}", "foo", 42)).isEqualTo("two args: foo and 42");
+ assertThat(ConsoleFormatter.format("args: {}, {} and {}", true, 42, 2L)).isEqualTo("args: true, 42 and 2");
+ }
+
+ @Test
+ public void only_static_methods() throws Exception {
+ assertThat(TestUtils.hasOnlyPrivateConstructors(ConsoleFormatter.class)).isTrue();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.PrintStream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
+public class ConsoleLoggerTest {
+
+ PrintStream stream = mock(PrintStream.class);
+ ConsoleLogger sut = new ConsoleLogger(stream);
+
+ @Rule
+ public LogTester tester = new LogTester();
+
+ @Test
+ public void debug_enabled() throws Exception {
+ tester.enableDebug(true);
+ assertThat(sut.isDebugEnabled()).isTrue();
+ sut.debug("message");
+ sut.debug("message {}", "foo");
+ sut.debug("message {} {}", "foo", "bar");
+ sut.debug("message {} {} {}", "foo", "bar", "baz");
+ verify(stream, times(4)).println(anyString());
+ }
+
+ @Test
+ public void debug_disabled() throws Exception {
+ tester.enableDebug(false);
+ assertThat(sut.isDebugEnabled()).isFalse();
+ sut.debug("message");
+ sut.debug("message {}", "foo");
+ sut.debug("message {} {}", "foo", "bar");
+ sut.debug("message {} {} {}", "foo", "bar", "baz");
+ verifyZeroInteractions(stream);
+ }
+
+ @Test
+ public void log() throws Exception {
+ sut.info("message");
+ sut.info("message {}", "foo");
+ sut.info("message {} {}", "foo", "bar");
+ sut.info("message {} {} {}", "foo", "bar", "baz");
+ verify(stream, times(4)).println(startsWith("INFO "));
+
+ sut.warn("message");
+ sut.warn("message {}", "foo");
+ sut.warn("message {} {}", "foo", "bar");
+ sut.warn("message {} {} {}", "foo", "bar", "baz");
+ verify(stream, times(4)).println(startsWith("WARN "));
+
+ sut.error("message");
+ sut.error("message {}", "foo");
+ sut.error("message {} {}", "foo", "bar");
+ sut.error("message {} {} {}", "foo", "bar", "baz");
+ sut.error("message", new IllegalArgumentException());
+ verify(stream, times(5)).println(startsWith("ERROR "));
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ConsoleLoggersTest {
+
+ ConsoleLoggers sut = new ConsoleLoggers();
+
+ @Test
+ public void newInstance() throws Exception {
+ Logger logger = sut.newInstance("foo");
+ assertThat(logger).isInstanceOf(ConsoleLogger.class);
+ }
+
+ @Test
+ public void debugMode() throws Exception {
+ // disabled by default
+ assertThat(sut.isDebugEnabled()).isFalse();
+
+ sut.enableDebug(true);
+ assertThat(sut.isDebugEnabled()).isTrue();
+
+ sut.enableDebug(false);
+ assertThat(sut.isDebugEnabled()).isFalse();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LogTesterTest {
+
+ LogTester sut = new LogTester();
+
+ @Test
+ public void debugLevel() throws Throwable {
+ boolean initial = sut.isDebugEnabled();
+
+ // when LogTester is used, then debug logs are enabled by default
+ sut.before();
+ assertThat(sut.isDebugEnabled()).isTrue();
+ assertThat(Loggers.getFactory().isDebugEnabled()).isTrue();
+
+ // change
+ sut.enableDebug(false);
+ assertThat(sut.isDebugEnabled()).isFalse();
+ assertThat(Loggers.getFactory().isDebugEnabled()).isFalse();
+
+ // reset to initial level
+ sut.after();
+ assertThat(sut.isDebugEnabled()).isEqualTo(initial);
+ assertThat(Loggers.getFactory().isDebugEnabled()).isEqualTo(initial);
+ }
+
+ @Test
+ public void intercept_logs() throws Throwable {
+ sut.before();
+ Loggers.get("logger1").info("an information");
+ Loggers.get("logger2").warn("warning: {}", 42);
+
+ assertThat(sut.logs()).containsExactly("an information", "warning: 42");
+
+ sut.after();
+ assertThat(LogInterceptor.instance).isSameAs(NullInterceptor.NULL_INSTANCE);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LogbackLoggerTest {
+
+ LogbackLogger sut = new LogbackLogger(LoggerFactory.getLogger(getClass()));
+
+ @Rule
+ public LogTester tester = new LogTester();
+
+ @Test
+ public void debug_enabling() throws Exception {
+ tester.enableDebug(true);
+ assertThat(sut.isDebugEnabled()).isTrue();
+
+ tester.enableDebug(false);
+ assertThat(sut.isDebugEnabled()).isFalse();
+ }
+
+ @Test
+ public void log() throws Exception {
+ // no assertions. Simply verify that calls do not fail.
+ sut.debug("message");
+ sut.debug("message {}", "foo");
+ sut.debug("message {} {}", "foo", "bar");
+ sut.debug("message {} {} {}", "foo", "bar", "baz");
+
+ sut.info("message");
+ sut.info("message {}", "foo");
+ sut.info("message {} {}", "foo", "bar");
+ sut.info("message {} {} {}", "foo", "bar", "baz");
+
+ sut.warn("message");
+ sut.warn("message {}", "foo");
+ sut.warn("message {} {}", "foo", "bar");
+ sut.warn("message {} {} {}", "foo", "bar", "baz");
+
+ sut.error("message");
+ sut.error("message {}", "foo");
+ sut.error("message {} {}", "foo", "bar");
+ sut.error("message {} {} {}", "foo", "bar", "baz");
+ sut.error("message", new IllegalArgumentException(""));
+
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.Test;
+import org.sonar.api.SonarPlugin;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LoggersTest {
+
+ @Test
+ public void factory() throws Exception {
+ // logback is used by sonar-plugin-api
+ assertThat(Loggers.getFactory()).isInstanceOf(LogbackLoggers.class);
+
+ assertThat(Loggers.get("foo")).isInstanceOf(LogbackLogger.class);
+ assertThat(Loggers.get(SonarPlugin.class)).isInstanceOf(LogbackLogger.class);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.utils.log;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+
+public class NullInterceptorTest {
+
+ @Test
+ public void do_nothing() throws Exception {
+ // verify that... it does nothing
+ NullInterceptor.NULL_INSTANCE.log("foo");
+ NullInterceptor.NULL_INSTANCE.log("foo {}", 42);
+ NullInterceptor.NULL_INSTANCE.log("foo {} {}", 42, 66);
+ NullInterceptor.NULL_INSTANCE.log("foo {} {} {}", 42, 66, 84);
+ NullInterceptor.NULL_INSTANCE.log("foo", mock(Exception.class));
+ }
+}