Search in sources :

Example 6 with Logger

use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.

the class LogarithmicLoggerTest method call_ratio_is_applied_before_logarithm.

@Test
public void call_ratio_is_applied_before_logarithm() {
    int callRatio = 10;
    Logger logarithmicLogger = LogarithmicLogger.from(Loggers.get(getClass())).applyingCallRatio(callRatio).build();
    for (int i = 0; i < 1000 + callRatio; i++) {
        logarithmicLogger.error(String.valueOf(i));
    }
    assertThat(logTester.logs(ERROR)).containsOnly("10", "30", "80", "210", "550");
    assertThat(logTester.logs()).containsOnly("10", "30", "80", "210", "550");
}
Also used : Logger(org.sonar.api.utils.log.Logger) Test(org.junit.Test)

Example 7 with Logger

use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.

the class TomcatAccessLogTest method log_when_started_and_stopped.

@Test
public void log_when_started_and_stopped() {
    Logger logger = mock(Logger.class);
    TomcatAccessLog.LifecycleLogger listener = new TomcatAccessLog.LifecycleLogger(logger);
    LifecycleEvent event = new LifecycleEvent(mock(Lifecycle.class), "before_init", null);
    listener.lifecycleEvent(event);
    verifyZeroInteractions(logger);
    event = new LifecycleEvent(mock(Lifecycle.class), "after_start", null);
    listener.lifecycleEvent(event);
    verify(logger).debug("Tomcat is started");
    event = new LifecycleEvent(mock(Lifecycle.class), "after_destroy", null);
    listener.lifecycleEvent(event);
    verify(logger).debug("Tomcat is stopped");
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) LifecycleEvent(org.apache.catalina.LifecycleEvent) Logger(org.sonar.api.utils.log.Logger) Test(org.junit.Test)

Example 8 with Logger

use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.

the class SecurityRealmFactory method start.

@Override
public void start() {
    if (realm != null) {
        Logger logger = Loggers.get("org.sonar.INFO");
        try {
            logger.info("Security realm: " + realm.getName());
            realm.init();
            logger.info("Security realm started");
        } catch (RuntimeException e) {
            if (ignoreStartupFailure) {
                logger.error("IGNORED - Security realm fails to start: " + e.getMessage());
            } else {
                throw new SonarException("Security realm fails to start: " + e.getMessage(), e);
            }
        }
    }
}
Also used : SonarException(org.sonar.api.utils.SonarException) Logger(org.sonar.api.utils.log.Logger)

Example 9 with Logger

use of org.sonar.api.utils.log.Logger in project sonarqube by SonarSource.

the class ValidationMessagesTest method emptyMessages.

@Test
public void emptyMessages() {
    ValidationMessages messages = ValidationMessages.create();
    assertThat(messages.hasErrors()).isFalse();
    assertThat(messages.hasWarnings()).isFalse();
    assertThat(messages.hasInfos()).isFalse();
    Logger logger = mock(Logger.class);
    messages.log(logger);
    verify(logger, never()).error(anyString());
    verify(logger, never()).warn(anyString());
    verify(logger, never()).info(anyString());
    org.slf4j.Logger slf4j = mock(org.slf4j.Logger.class);
    messages.log(slf4j);
    verify(slf4j, never()).error(anyString());
    verify(slf4j, never()).warn(anyString());
    verify(slf4j, never()).info(anyString());
}
Also used : Logger(org.sonar.api.utils.log.Logger) Test(org.junit.Test)

Aggregations

Logger (org.sonar.api.utils.log.Logger)9 Test (org.junit.Test)7 Lifecycle (org.apache.catalina.Lifecycle)1 LifecycleEvent (org.apache.catalina.LifecycleEvent)1 SonarException (org.sonar.api.utils.SonarException)1