当前位置: 首页>>代码示例>>Java>>正文


Java ThresholdFilter.createFilter方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.filter.ThresholdFilter.createFilter方法的典型用法代码示例。如果您正苦于以下问题:Java ThresholdFilter.createFilter方法的具体用法?Java ThresholdFilter.createFilter怎么用?Java ThresholdFilter.createFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.core.filter.ThresholdFilter的用法示例。


在下文中一共展示了ThresholdFilter.createFilter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerListener

import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入方法依赖的package包/类
@Override
public void registerListener(ListenerConfig cfg) {
  if (history != null)
    throw new IllegalStateException("History already registered");

  history = new CircularList<LogEvent>(cfg.size);

  Level threshold = (cfg.threshold != null) ? Level.toLevel(cfg.threshold) : Level.WARN;
  ThresholdFilter filter = ThresholdFilter.createFilter(threshold, Filter.Result.ACCEPT, Filter.Result.DENY);
  appender = new Log4j2Appender(this, filter, threshold);
  if (!appender.isStarted())
    appender.start();

  LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  LoggerConfig config = getLoggerConfig(ctx, LoggerInfo.ROOT_NAME);
  config.addAppender(appender, threshold, filter);
  ctx.updateLoggers();
}
 
开发者ID:lucidworks,项目名称:solr-log4j2,代码行数:19,代码来源:Log4j2Watcher.java

示例2: init

import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public static synchronized void init() {
	final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	final Configuration config = ctx.getConfiguration();
	Layout layout = PatternLayout.newBuilder().withPattern("%d{yyyy-MM-dd HH:mm:ss}:%p %t %c - %m%n")
			.withConfiguration(config).withRegexReplacement(null).withCharset(null).withAlwaysWriteExceptions(true)
			.withNoConsoleNoAnsi(false).withHeader(null).withFooter(null).build();

	// file info
	Filter fileInfoFilter = ThresholdFilter.createFilter(Level.ERROR, Result.DENY, Result.ACCEPT);
	Appender fileInfoAppender = RollingFileAppender.createAppender(LOG_ROOT + "/zebra.log",
			LOG_ROOT + "/zebra.log.%d{yyyy-MM-dd}.gz", "true", "FileInfo", "true", "4000", "true",
			TimeBasedTriggeringPolicy.createPolicy("1", "true"),
			ZebraRolloverStrategy.createStrategy("30", "1", null, Deflater.DEFAULT_COMPRESSION + "", config),
			layout, fileInfoFilter, "false", null, null, config);
	config.addAppender(fileInfoAppender);
	fileInfoAppender.start();
	AppenderRef fileInfoRef = AppenderRef.createAppenderRef("FileInfo", null, fileInfoFilter);

	// console error
	Appender consoleErrorAppender = ConsoleAppender.createAppender(layout, null, "SYSTEM_ERR", "ConsoleError",
			"false", "false");
	config.addAppender(consoleErrorAppender);
	consoleErrorAppender.start();

	// console info
	Filter consoleWarnFilter = ThresholdFilter.createFilter(Level.ERROR, Result.DENY, Result.NEUTRAL);
	Appender consoleWarnAppender = ConsoleAppender.createAppender(layout, consoleWarnFilter, "SYSTEM_OUT",
			"ConsoleWarn", "false", "false");
	config.addAppender(consoleWarnAppender);
	consoleWarnAppender.start();
	AppenderRef consoleWarnAppenderRef = AppenderRef.createAppenderRef("ConsoleWarn", Level.WARN,
			consoleWarnFilter);
	AppenderRef consoleErrorAppenderRef = AppenderRef.createAppenderRef("ConsoleError", Level.WARN, null);

	AppenderRef[] refs = new AppenderRef[] { consoleErrorAppenderRef, consoleWarnAppenderRef, fileInfoRef };

	LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "com.dianping.zebra", "true", refs,
			null, config, null);
	loggerConfig.addAppender(consoleErrorAppender, Level.ERROR, null);
	loggerConfig.addAppender(consoleWarnAppender, Level.INFO, null);
	loggerConfig.addAppender(fileInfoAppender, Level.INFO, null);

	config.addLogger("com.dianping.zebra", loggerConfig);

	ctx.updateLoggers();

	context = ctx;
}
 
开发者ID:dianping,项目名称:zebra,代码行数:50,代码来源:LoggerLoader.java

示例3: DirectConsumingAppender

import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入方法依赖的package包/类
public DirectConsumingAppender(String name, Consumer<byte[]> logEventConsumer, Level threshold) {
    super(name, ThresholdFilter.createFilter(threshold, Filter.Result.ACCEPT, Filter.Result.DENY), LAYOUT, false);
    this.logEventConsumer = requireNonNull(logEventConsumer);
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-internal-logs,代码行数:5,代码来源:DirectConsumingAppender.java

示例4: setThreshold

import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入方法依赖的package包/类
public void setThreshold(Level threshold) {
  this.threshold = threshold;
  removeFilter(filter);
  filter = ThresholdFilter.createFilter(threshold, Filter.Result.ACCEPT, Filter.Result.DENY);
  addFilter(filter);
}
 
开发者ID:lucidworks,项目名称:solr-log4j2,代码行数:7,代码来源:Log4j2Watcher.java

示例5: createAppender

import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入方法依赖的package包/类
@PluginFactory
public static <S extends Serializable> GelfConsoleAppender<S> createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("facility") final String facility,
        @PluginAttribute("target") final String t,
        @PluginAttribute("extractStacktrace") final String extractStacktrace,
        @PluginAttribute("originHost") final String originHost,
        @PluginAttribute("addExtendedInformation") final String addExtendedInformation,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginAttribute("additionalFields") final String additionalFields,
        @PluginElement("layout") Layout<S> layout,
        @PluginElement("filter") Filter filter,
        @PluginAttribute("suppressExceptions") final String suppressExceptions) throws IOException {

    if (name == null) {
        LOGGER.error("No name provided for GelfConsoleAppender");
        return null;
    }

    GelfSender gelfSender = null;

    final boolean isHandleExceptions = suppressExceptions == null ? true : Boolean.valueOf(suppressExceptions);

    if (layout == null) {
        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
        Layout<S> l = (Layout<S>) HTMLLayout.createLayout(null, null, null, null, null, null);
        layout = l;
    }
    if (filter == null) {
        filter = ThresholdFilter.createFilter("INFO", null, null);
    }

    // If target is set properly, use it. Otherwise use SYSTEM_OUT
    final Target target = t == null ? Target.SYSTEM_OUT : Target.valueOf(t);

    gelfSender = getGelfConsoleSender(target);

    if (gelfSender == null) { return null; }

    GelfConsoleAppender gelfConsoleAppender = new GelfConsoleAppender<S>(name, filter, layout, gelfSender, isHandleExceptions);
    gelfConsoleAppender.setFacility(facility);
    gelfConsoleAppender.setExtractStacktrace(Boolean.parseBoolean(extractStacktrace));
    gelfConsoleAppender.setOriginHost(originHost);
    gelfConsoleAppender.setAddExtendedInformation(Boolean.parseBoolean(addExtendedInformation));
    gelfConsoleAppender.setIncludeLocation(Boolean.parseBoolean(includeLocation));
    gelfConsoleAppender.setAdditionalFields(additionalFields);

    return gelfConsoleAppender;
}
 
开发者ID:mashintsev,项目名称:gelfj2,代码行数:50,代码来源:GelfConsoleAppender.java

示例6: Log4JConsoleStream

import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入方法依赖的package包/类
public Log4JConsoleStream(UniversalMinecraftAPIInterface uma) {
    uma.getStreamManager().registerStream("console");

    Logger rootLogger = (Logger) LogManager.getRootLogger();

    Layout<? extends Serializable> layout = Optional.ofNullable(rootLogger.getAppenders().get("Console")).map(Appender::getLayout).orElse(null);

    if (layout == null) {
        layout = PatternLayout.createLayout("[%d{HH:mm:ss} %level] [%logger{1}]: %msg%n", null, null, null, null);
    }

    Filter infoFilter = ThresholdFilter.createFilter("INFO", "ACCEPT", "DENY");
    Filter warnFilter = ThresholdFilter.createFilter("WARN", "ACCEPT", "DENY");

    rootLogger.addAppender(new Log4JConsoleStreamAppender(uma, ThresholdFilter.createFilter("INFO", "ACCEPT", "DENY"), layout));

    Logger minecraftLogger = (Logger) LogManager.getLogger("net.minecraft");

    Layout<? extends Serializable> minecraftLayout;

    minecraftLayout = Optional.ofNullable(minecraftLogger.getAppenders().get("Console")).map(Appender::getLayout).orElse(null);

    if (minecraftLayout == null) {
        minecraftLayout = PatternLayout.createLayout("[%d{HH:mm:ss} %level]: %msg%n", null, null, null, null);
    }

    Appender minecraftAppender = new Log4JConsoleStreamAppender(uma, infoFilter, minecraftLayout);

    minecraftLogger.addAppender(minecraftAppender);

    ((Logger) LogManager.getLogger("com.mojang")).addAppender(minecraftAppender);

    Appender warnAppender = new Log4JConsoleStreamAppender(uma, warnFilter, layout);

    ((Logger) LogManager.getLogger("LaunchWrapper")).addAppender(warnAppender);
    ((Logger) LogManager.getLogger("com.zaxxer.hikari")).addAppender(warnAppender);
}
 
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:38,代码来源:Log4JConsoleStream.java


注:本文中的org.apache.logging.log4j.core.filter.ThresholdFilter.createFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。