abstract class BaseLogger implements Logger {
@Override
public void trace(String msg) {
- LogInterceptor.instance().log(msg);
+ LogInterceptors.get().log(msg);
doTrace(msg);
}
@Override
public void trace(String pattern, @Nullable Object arg) {
- LogInterceptor.instance().log(pattern, arg);
+ LogInterceptors.get().log(pattern, arg);
doTrace(pattern, arg);
}
@Override
public void trace(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- LogInterceptor.instance().log(msg, arg1, arg2);
+ LogInterceptors.get().log(msg, arg1, arg2);
doTrace(msg, arg1, arg2);
}
@Override
public void trace(String msg, Object... args) {
- LogInterceptor.instance().log(msg, args);
+ LogInterceptors.get().log(msg, args);
doTrace(msg, args);
}
@Override
public void debug(String msg) {
- LogInterceptor.instance().log(msg);
+ LogInterceptors.get().log(msg);
doDebug(msg);
}
@Override
public void debug(String pattern, @Nullable Object arg) {
- LogInterceptor.instance().log(pattern, arg);
+ LogInterceptors.get().log(pattern, arg);
doDebug(pattern, arg);
}
@Override
public void debug(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- LogInterceptor.instance().log(msg, arg1, arg2);
+ LogInterceptors.get().log(msg, arg1, arg2);
doDebug(msg, arg1, arg2);
}
@Override
public void debug(String msg, Object... args) {
- LogInterceptor.instance().log(msg, args);
+ LogInterceptors.get().log(msg, args);
doDebug(msg, args);
}
@Override
public void info(String msg) {
- LogInterceptor.instance().log(msg);
+ LogInterceptors.get().log(msg);
doInfo(msg);
}
@Override
public void info(String msg, @Nullable Object arg) {
- LogInterceptor.instance().log(msg, arg);
+ LogInterceptors.get().log(msg, arg);
doInfo(msg, arg);
}
@Override
public void info(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- LogInterceptor.instance().log(msg, arg1, arg2);
+ LogInterceptors.get().log(msg, arg1, arg2);
doInfo(msg, arg1, arg2);
}
@Override
public void info(String msg, Object... args) {
- LogInterceptor.instance().log(msg, args);
+ LogInterceptors.get().log(msg, args);
doInfo(msg, args);
}
@Override
public void warn(String msg) {
- LogInterceptor.instance().log(msg);
+ LogInterceptors.get().log(msg);
doWarn(msg);
}
@Override
public void warn(String msg, @Nullable Object arg) {
- LogInterceptor.instance().log(msg, arg);
+ LogInterceptors.get().log(msg, arg);
doWarn(msg, arg);
}
@Override
public void warn(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- LogInterceptor.instance().log(msg, arg1, arg2);
+ LogInterceptors.get().log(msg, arg1, arg2);
doWarn(msg, arg1, arg2);
}
@Override
public void warn(String msg, Object... args) {
- LogInterceptor.instance().log(msg, args);
+ LogInterceptors.get().log(msg, args);
doWarn(msg, args);
}
@Override
public void error(String msg) {
- LogInterceptor.instance().log(msg);
+ LogInterceptors.get().log(msg);
doError(msg);
}
@Override
public void error(String msg, @Nullable Object arg) {
- LogInterceptor.instance().log(msg, arg);
+ LogInterceptors.get().log(msg, arg);
doError(msg, arg);
}
@Override
public void error(String msg, @Nullable Object arg1, @Nullable Object arg2) {
- LogInterceptor.instance().log(msg, arg1, arg2);
+ LogInterceptors.get().log(msg, arg1, arg2);
doError(msg, arg1, arg2);
}
@Override
public void error(String msg, Object... args) {
- LogInterceptor.instance().log(msg, args);
+ LogInterceptors.get().log(msg, args);
doError(msg, args);
}
@Override
public void error(String msg, Throwable thrown) {
- LogInterceptor.instance().log(msg, thrown);
+ LogInterceptors.get().log(msg, thrown);
doError(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 com.google.common.base.Preconditions;
+
+class LogInterceptors {
+
+ private static LogInterceptor instance = NullInterceptor.NULL_INSTANCE;
+
+ private LogInterceptors() {
+ }
+
+ static LogInterceptor get() {
+ return instance;
+ }
+
+ static void set(LogInterceptor li) {
+ Preconditions.checkArgument(li != null);
+ instance = li;
+ }
+}
--- /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 LogInterceptorsTest {
+
+ @Test
+ public void default_is_null_interceptor() throws Exception {
+ // production-ready
+ assertThat(LogInterceptors.get()).isInstanceOf(NullInterceptor.class);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void instance_cant_be_null() throws Exception {
+ LogInterceptors.set(null);
+ }
+}