use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.
the class ComponentKeysTest method should_log_warning_if_toString_is_not_overridden.
@Test
public void should_log_warning_if_toString_is_not_overridden() {
Logger log = mock(Logger.class);
keys.of(new Object(), log);
verifyZeroInteractions(log);
// only on non-first runs, to avoid false-positives on singletons
keys.of(new Object(), log);
verify(log).warn(startsWith("Bad component key"));
}
use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.
the class ProgressLogger method create.
public static ProgressLogger create(Class clazz, AtomicLong counter) {
String threadName = String.format("ProgressLogger[%s]", clazz.getSimpleName());
Logger logger = Loggers.get(clazz);
return new ProgressLogger(threadName, counter, logger);
}
use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.
the class ValidationMessagesTest method addError.
@Test
public void addError() {
ValidationMessages messages = ValidationMessages.create();
messages.addErrorText("my error");
assertThat(messages.hasErrors()).isTrue();
assertThat(messages.hasWarnings()).isFalse();
assertThat(messages.hasInfos()).isFalse();
assertThat(messages.getErrors()).hasSize(1);
assertThat(messages.getErrors()).contains("my error");
assertThat(messages.toString()).contains("my error");
Logger logger = mock(Logger.class);
messages.log(logger);
verify(logger, times(1)).error("my error");
verify(logger, never()).warn(anyString());
verify(logger, never()).info(anyString());
org.slf4j.Logger slf4j = mock(org.slf4j.Logger.class);
messages.log(slf4j);
verify(slf4j, times(1)).error("my error");
verify(slf4j, never()).warn(anyString());
verify(slf4j, never()).info(anyString());
}
use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.
the class LogarithmicLoggerTest method logarithmically_logs_less_and_less_frequently_calls_to_same_Logger_method.
@Test
public void logarithmically_logs_less_and_less_frequently_calls_to_same_Logger_method() throws InterruptedException {
Logger logarithmicLogger = LogarithmicLogger.from(Loggers.get(getClass())).build();
for (int i = 0; i < 1000; i++) {
logarithmicLogger.error(String.valueOf(i));
}
assertThat(logTester.logs(ERROR)).containsOnly("1", "3", "8", "21", "55", "149", "404");
assertThat(logTester.logs()).containsOnly("1", "3", "8", "21", "55", "149", "404");
}
use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.
the class LogarithmicLoggerTest method logarithmically_logs_less_and_less_frequently_calls_across_log_levels.
@Test
public void logarithmically_logs_less_and_less_frequently_calls_across_log_levels() throws InterruptedException {
Logger logarithmicLogger = LogarithmicLogger.from(Loggers.get(getClass())).build();
for (int i = 0; i < 1000; i++) {
spawnMessageOnLevels(logarithmicLogger, i, String.valueOf(i));
}
assertThat(logTester.logs()).containsOnly("1", "3", "8", "21", "55", "149", "404");
assertThat(logTester.logs(ERROR)).containsOnly("55");
assertThat(logTester.logs(WARN)).containsOnly("1", "21");
assertThat(logTester.logs(INFO)).isEmpty();
assertThat(logTester.logs(DEBUG)).containsOnly("3", "8");
assertThat(logTester.logs(TRACE)).containsOnly("149", "404");
}
Aggregations