Search in sources :

Example 91 with Appender

use of ch.qos.logback.core.Appender in project atlasdb by palantir.

the class ProfilingKeyValueServiceTest method dropTableSlowLogPresentOnInfoLevel.

@Test
public void dropTableSlowLogPresentOnInfoLevel() {
    Appender mockAppender = setLogLevelAndGetAppender(Level.INFO);
    doAnswer(waitASecondAndAHalf).when(delegate).dropTable(any());
    kvs.dropTable(TABLE_REF);
    verify(mockAppender).doAppend(slowLogMatcher.get());
}
Also used : Appender(ch.qos.logback.core.Appender) Test(org.junit.Test)

Example 92 with Appender

use of ch.qos.logback.core.Appender in project atlasdb by palantir.

the class ProfilingKeyValueServiceTest method dropTableTraceLogPresentOnTraceLevelEvenIfQueryIsSlow.

@Test
public void dropTableTraceLogPresentOnTraceLevelEvenIfQueryIsSlow() {
    Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE);
    doAnswer(waitASecondAndAHalf).when(delegate).dropTable(any());
    kvs.dropTable(TABLE_REF);
    verify(mockAppender).doAppend(traceLogMatcher.get());
    verify(mockAppender).doAppend(slowLogMatcher.get());
}
Also used : Appender(ch.qos.logback.core.Appender) Test(org.junit.Test)

Example 93 with Appender

use of ch.qos.logback.core.Appender in project candlepin by candlepin.

the class StatusResourceTest method simulateVersionFilter.

@Test
public void simulateVersionFilter() throws Exception {
    // setup logger to see if we actually log anything
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger srLogger = lc.getLogger(StatusResource.class);
    Appender mockapp = mock(Appender.class);
    srLogger.addAppender(mockapp);
    srLogger.setLevel(Level.DEBUG);
    ArgumentCaptor<LoggingEvent> message = ArgumentCaptor.forClass(LoggingEvent.class);
    PrintStream ps = new PrintStream(new File(this.getClass().getClassLoader().getResource("version.properties").toURI()));
    ps.println("version=${version}");
    ps.println("release=${release}");
    StatusResource sr = new StatusResource(rulesCurator, config, jsProvider, candlepinCache, modeManager);
    Status s = sr.status();
    ps.close();
    // make sure we did not log anything which indicates
    // an exception
    verify(mockapp, never()).doAppend(message.capture());
    assertEquals("${release}", s.getRelease());
    assertEquals("${version}", s.getVersion());
    assertTrue(s.getResult());
    assertFalse(s.getStandalone());
}
Also used : Appender(ch.qos.logback.core.Appender) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) Status(org.candlepin.model.Status) PrintStream(java.io.PrintStream) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) File(java.io.File) Test(org.junit.Test)

Example 94 with Appender

use of ch.qos.logback.core.Appender in project kie-wb-common by kiegroup.

the class LogbackConfig method setSiftingAppender.

private SiftingAppender setSiftingAppender(LoggerContext loggerContext, Discriminator discriminator) {
    KieSiftingAppender appender = new KieSiftingAppender();
    appender.setName(MavenConfig.COMPILATION_ID);
    appender.setDiscriminator(discriminator);
    appender.setAppenderFactory(new AppenderFactory<ILoggingEvent>() {

        @Override
        public Appender<ILoggingEvent> buildAppender(Context context, String discriminatingValue) throws JoranException {
            KieSiftingAppender kieAppender = new KieSiftingAppender();
            kieAppender.setName(discriminatingValue);
            kieAppender.setContext(loggerContext);
            return kieAppender;
        }
    });
    appender.setContext(loggerContext);
    appender.start();
    return appender;
}
Also used : Context(ch.qos.logback.core.Context) LoggerContext(ch.qos.logback.classic.LoggerContext) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) KieSiftingAppender(org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender) Appender(ch.qos.logback.core.Appender) SiftingAppender(ch.qos.logback.classic.sift.SiftingAppender) JoranException(ch.qos.logback.core.joran.spi.JoranException) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KieSiftingAppender(org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender)

Example 95 with Appender

use of ch.qos.logback.core.Appender in project cuba by cuba-platform.

the class LogControlImpl method getAppenderThreshold.

@Override
public Level getAppenderThreshold(String appenderName) throws AppenderThresholdNotSupported {
    for (Map.Entry<String, Appender> entry : getAllAppenders().entrySet()) {
        if (entry.getKey().equals(appenderName)) {
            Appender appender = entry.getValue();
            for (Object filter : appender.getCopyOfAttachedFiltersList()) {
                if (filter instanceof ThresholdFilter) {
                    try {
                        Field field = filter.getClass().getDeclaredField("level");
                        field.setAccessible(true);
                        return (Level) field.get(filter);
                    } catch (NoSuchFieldException | IllegalAccessException e) {
                        log.error("Error getting appender " + appenderName + " level", e);
                        throw new AppenderThresholdNotSupported(appenderName);
                    }
                }
            }
        }
    }
    throw new AppenderThresholdNotSupported(appenderName);
}
Also used : Appender(ch.qos.logback.core.Appender) ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) Field(java.lang.reflect.Field) Level(ch.qos.logback.classic.Level) AppenderThresholdNotSupported(com.haulmont.cuba.core.sys.logging.AppenderThresholdNotSupported)

Aggregations

Appender (ch.qos.logback.core.Appender)118 Test (org.junit.Test)62 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)51 Logger (ch.qos.logback.classic.Logger)32 LoggerContext (ch.qos.logback.classic.LoggerContext)32 FileAppender (ch.qos.logback.core.FileAppender)27 Logger (org.slf4j.Logger)25 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)21 ArgumentMatcher (org.mockito.ArgumentMatcher)19 AsyncAppender (ch.qos.logback.classic.AsyncAppender)18 File (java.io.File)14 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13 LogstashTcpSocketAppender (net.logstash.logback.appender.LogstashTcpSocketAppender)13 ArrayList (java.util.ArrayList)11 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)11 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)9 DBAppender (ch.qos.logback.classic.db.DBAppender)8 Test (org.junit.jupiter.api.Test)7