*/
package org.sonar.api.utils.log;
-import org.junit.rules.ExternalResource;
-
import java.util.List;
+import org.junit.rules.ExternalResource;
/**
* <b>For tests only</b>
*/
public class LogTester extends ExternalResource {
- private LoggerLevel initialLevel;
-
@Override
protected void before() throws Throwable {
- initialLevel = Loggers.getFactory().getLevel();
-
// this shared instance breaks compatibility with parallel execution of tests
LogInterceptors.set(new ListInterceptor());
setLevel(LoggerLevel.INFO);
@Override
protected void after() {
LogInterceptors.set(NullInterceptor.NULL_INSTANCE);
- setLevel(initialLevel);
+ setLevel(LoggerLevel.INFO);
}
LoggerLevel getLevel() {
/**
* Enable/disable debug logs. Info, warn and error logs are always enabled.
- * By default debug logs are enabled when LogTester is started.
+ * By default INFO logs are enabled when LogTester is started.
*/
public LogTester setLevel(LoggerLevel level) {
Loggers.getFactory().setLevel(level);
@Test
public void info_level_by_default() throws Throwable {
- LoggerLevel initial = underTest.getLevel();
-
// when LogTester is used, then info logs are enabled by default
underTest.before();
assertThat(underTest.getLevel()).isEqualTo(LoggerLevel.INFO);
// reset to initial level after execution of test
underTest.after();
- assertThat(underTest.getLevel()).isEqualTo(initial);
- assertThat(Loggers.getFactory().getLevel()).isEqualTo(initial);
+ assertThat(underTest.getLevel()).isEqualTo(LoggerLevel.INFO);
+ assertThat(Loggers.getFactory().getLevel()).isEqualTo(LoggerLevel.INFO);
}
@Test