Java Code Examples for ch.qos.logback.classic.filter.ThresholdFilter#start()
The following examples show how to use
ch.qos.logback.classic.filter.ThresholdFilter#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiagnosticLogger.java From synopsys-detect with Apache License 2.0 | 7 votes |
private FileAppender<ILoggingEvent> addAppender(final String file) { final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); final PatternLayoutEncoder ple = new PatternLayoutEncoder(); ple.setPattern("%date %level [%file:%line] %msg%n"); ple.setContext(lc); ple.start(); final FileAppender<ILoggingEvent> appender; appender = new FileAppender<>(); appender.setFile(file); appender.setEncoder(ple); appender.setContext(lc); final ThresholdFilter levelFilter = new ThresholdFilter(); levelFilter.setLevel(this.level.levelStr); levelFilter.start(); appender.addFilter(levelFilter); appender.start(); final ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); logbackLogger.addAppender(appender); return appender; }
Example 2
Source File: LogAppender.java From nuls-v2 with MIT License | 6 votes |
@SuppressWarnings("unchecked") public static Appender<ILoggingEvent> createConsoleAppender(Level level){ ConsoleAppender appender = new ConsoleAppender(); LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); appender.setContext(context); //这里设置级别过滤器 LogFilter levelController = new LogFilter(); ThresholdFilter levelFilter = levelController.getThresholdFilter(level); levelFilter.start(); appender.addFilter(levelFilter); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); //设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 //但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。 encoder.setContext(context); //设置格式 encoder.setPattern("%d %p [%t] - %msg%n"); encoder.start(); //加入下面两个节点 appender.setEncoder(encoder); appender.start(); return appender; }
Example 3
Source File: SentryConfiguration.java From Lavalink with MIT License | 6 votes |
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; }
Example 4
Source File: LoggingConfigurator.java From logging-java with Apache License 2.0 | 6 votes |
/** * Add a sentry appender. * @param dsn the sentry dsn to use (as produced by the sentry webinterface). * @param logLevelThreshold the threshold for log events to be sent to sentry. * @return the configured sentry appender. */ public static SentryAppender addSentryAppender(final String dsn, Level logLevelThreshold) { final Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); final LoggerContext context = rootLogger.getLoggerContext(); SentryAppender appender = new SentryAppender(); appender.setDsn(dsn); appender.setContext(context); ThresholdFilter levelFilter = new ThresholdFilter(); levelFilter.setLevel(logLevelThreshold.logbackLevel.toString()); levelFilter.start(); appender.addFilter(levelFilter); appender.start(); rootLogger.addAppender(appender); return appender; }
Example 5
Source File: DiagnosticLogSystem.java From synopsys-detect with Apache License 2.0 | 5 votes |
private void restrictConsoleToDebug() { for (final Iterator<Appender<ILoggingEvent>> it = DiagnosticLogUtil.getRootLogger().iteratorForAppenders(); it.hasNext(); ) { final Appender appender = it.next(); if (appender.getName() != null && appender.getName().equals("CONSOLE")) { final ThresholdFilter levelFilter = new ThresholdFilter(); levelFilter.setLevel(Level.DEBUG.levelStr); levelFilter.start(); appender.addFilter(levelFilter); } } }
Example 6
Source File: LogAppender.java From nuls-v2 with MIT License | 4 votes |
/** * 通过传入的名字和级别,动态设置appender * * @param fileName * @return */ @SuppressWarnings("unchecked") public static RollingFileAppender getAppender(String fileName, Level level){ String rootPath = PROJECT_PATH; if(!rootPath.endsWith(File.separator)){ rootPath += File.separator; } if(fileName.startsWith(File.separator)){ fileName = fileName.substring(1); } LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); RollingFileAppender appender = new RollingFileAppender(); /*设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。*/ appender.setContext(context); //这里设置级别过滤器 LogFilter levelController = new LogFilter(); ThresholdFilter levelFilter = levelController.getThresholdFilter(level); levelFilter.start(); appender.addFilter(levelFilter); //设置文件名 appender.setFile(OptionHelper.substVars(rootPath+fileName + ".log",context)); appender.setAppend(true); appender.setPrudent(false); //设置文件创建时间及大小的类 SizeAndTimeBasedRollingPolicy policy = new SizeAndTimeBasedRollingPolicy(); //文件名格式 String fp = OptionHelper.substVars(rootPath+ fileName + ".%d{yyyy-MM-dd}.%i.zip",context); //最大日志文件大小 policy.setMaxFileSize(FileSize.valueOf("100MB")); //设置文件名模式 policy.setFileNamePattern(fp); //设置保存最近3天的日志 policy.setMaxHistory(3); //总大小限制 policy.setContext(context); policy.setTotalSizeCap(FileSize.valueOf("1GB")); //设置父节点是appender policy.setParent(appender); //设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 //但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。 policy.start(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); //设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 //但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。 encoder.setContext(context); //设置格式 /*encoder.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] %replace(%caller{1}){'\\t|Caller.{1}0|\\r\\n', ''} - %msg%n");*/ encoder.setPattern("%d %p [%t] - %msg%n"); encoder.start(); //加入下面两个节点 appender.setRollingPolicy(policy); appender.setEncoder(encoder); appender.start(); return appender; }
Example 7
Source File: LogbackFactory.java From bither-desktop-java with Apache License 2.0 | 4 votes |
private static void addThresholdFilter(FilterAttachable<ILoggingEvent> appender, Level threshold) { final ThresholdFilter filter = new ThresholdFilter(); filter.setLevel(threshold.toString()); filter.start(); appender.addFilter(filter); }
Example 8
Source File: LogbackFactory.java From bither-desktop-java with Apache License 2.0 | 4 votes |
private static void addThresholdFilter(FilterAttachable<ILoggingEvent> appender, Level threshold) { final ThresholdFilter filter = new ThresholdFilter(); filter.setLevel(threshold.toString()); filter.start(); appender.addFilter(filter); }