Search in sources :

Example 1 with SentryAppender

use of io.sentry.logback.SentryAppender in project FredBoat by Frederikam.

the class SentryConfiguration method getSentryLogbackAppender.

// programmatically creates a sentry appender
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 2 with SentryAppender

use of io.sentry.logback.SentryAppender 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)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)2 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)2 SentryAppender (io.sentry.logback.SentryAppender)2