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);
}
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());
}
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;
}
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();
}
}
Aggregations