本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}