Search in sources :

Example 11 with ThresholdFilter

use of ch.qos.logback.classic.filter.ThresholdFilter 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)

Example 12 with ThresholdFilter

use of ch.qos.logback.classic.filter.ThresholdFilter in project AJSC by att.

the class loggingConfigurationTest method getFilterInstanceTest.

@Test
public void getFilterInstanceTest() {
    System.out.println("Running getFilterInstanceTest");
    LoggingConfigurationService l = new LoggingConfigurationService();
    l.init();
    ThresholdFilter d = (ThresholdFilter) l.getFilterInstance(null);
    assertEquals("ch.qos.logback.classic.filter.ThresholdFilter", d.getClass().getName());
}
Also used : ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) Test(org.junit.Test)

Example 13 with ThresholdFilter

use of ch.qos.logback.classic.filter.ThresholdFilter in project Backend by FredBoat.

the class SentryConfiguration method getSentryLogbackAppender.

// programmatically creates a sentry appender if it doesn't exist yet
private static synchronized SentryAppender getSentryLogbackAppender() {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    ch.qos.logback.classic.Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    SentryAppender sentryAppender = (SentryAppender) root.getAppender(SENTRY_APPENDER_NAME);
    if (sentryAppender == null) {
        sentryAppender = new SentryAppender();
        sentryAppender.setName(SENTRY_APPENDER_NAME);
        ThresholdFilter warningsOrAboveFilter = new ThresholdFilter();
        warningsOrAboveFilter.setLevel(Level.WARN.levelStr);
        warningsOrAboveFilter.start();
        sentryAppender.addFilter(warningsOrAboveFilter);
        sentryAppender.setContext(loggerContext);
        root.addAppender(sentryAppender);
    }
    return sentryAppender;
}
Also used : ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) SentryAppender(io.sentry.logback.SentryAppender) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 14 with ThresholdFilter

use of ch.qos.logback.classic.filter.ThresholdFilter in project dropwizard by dropwizard.

the class BootstrapLogging method bootstrap.

public static void bootstrap(Level level, DiscoverableLayoutFactory<ILoggingEvent> layoutFactory) {
    LoggingUtil.hijackJDKLogging();
    BOOTSTRAPPING_LOCK.lock();
    try {
        if (bootstrapped) {
            return;
        }
        final Logger root = LoggingUtil.getLoggerContext().getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
        root.detachAndStopAllAppenders();
        final Layout<ILoggingEvent> layout = layoutFactory.build(root.getLoggerContext(), TimeZone.getDefault());
        layout.start();
        final ThresholdFilter filter = new ThresholdFilter();
        filter.setLevel(level.toString());
        filter.start();
        final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
        appender.addFilter(filter);
        appender.setContext(root.getLoggerContext());
        final LayoutWrappingEncoder<ILoggingEvent> layoutEncoder = new LayoutWrappingEncoder<>();
        layoutEncoder.setLayout(layout);
        appender.setEncoder(layoutEncoder);
        appender.start();
        root.addAppender(appender);
        bootstrapped = true;
    } finally {
        BOOTSTRAPPING_LOCK.unlock();
    }
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LayoutWrappingEncoder(ch.qos.logback.core.encoder.LayoutWrappingEncoder)

Aggregations

ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)14 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)5 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)5 LoggerContext (ch.qos.logback.classic.LoggerContext)4 Test (org.junit.Test)4 Logger (ch.qos.logback.classic.Logger)3 Appender (ch.qos.logback.core.Appender)3 Level (ch.qos.logback.classic.Level)2 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)2 FileAppender (ch.qos.logback.core.FileAppender)2 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)2 LayoutWrappingEncoder (ch.qos.logback.core.encoder.LayoutWrappingEncoder)2 SentryAppender (io.sentry.logback.SentryAppender)2 Field (java.lang.reflect.Field)2 PmsConfiguration (net.pms.configuration.PmsConfiguration)2 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)1 Filter (ch.qos.logback.core.filter.Filter)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1