本文整理汇总了Java中org.apache.logging.log4j.core.filter.ThresholdFilter类的典型用法代码示例。如果您正苦于以下问题:Java ThresholdFilter类的具体用法?Java ThresholdFilter怎么用?Java ThresholdFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThresholdFilter类属于org.apache.logging.log4j.core.filter包,在下文中一共展示了ThresholdFilter类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: testConfiguration
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
@Test
public void testConfiguration() {
final Configuration configuration = context.getConfiguration();
assertNotNull(configuration);
final FileAppender appender = configuration.getAppender("info");
assertNotNull(appender);
final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
assertNotNull(compFilter);
final Filter[] filters = compFilter.getFiltersArray();
assertNotNull(filters);
boolean foundLevel = false;
for (final Filter filter : filters) {
final ThresholdFilter tFilter = (ThresholdFilter) filter;
if (infom1Level.equals(tFilter.getLevel())) {
foundLevel = true;
break;
}
}
Assert.assertTrue("Level not found: " + infom1Level, foundLevel);
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:CustomLevelsWithFiltersTest.java
示例3: testPropertiesConfiguration
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:PropertiesConfigurationTest.java
示例4: testPropertiesConfiguration
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:PropertiesConfigurationRootLoggerOnlyTest.java
示例5: testPropertiesConfiguration
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
assertEquals("Incorrect level " + logger.getLevel(), Level.DEBUG, logger.getLevel());
logger.debug("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:PropertiesConfigurationTrailingSpaceOnLevelTest.java
示例6: testPropertiesConfiguration
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:RollingFilePropertiesTest.java
示例7: createTestElasticsearchAppenderBuilder
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
public static Builder createTestElasticsearchAppenderBuilder() {
Builder builder = ElasticsearchAppender.newBuilder();
builder.withName(TEST_APPENDER_NAME);
builder.withFilter(ThresholdFilter.createFilter(Level.INFO, Filter.Result.ACCEPT, Filter.Result.DENY));
builder.withIgnoreExceptions(false);
builder.withBatchDelivery(mock(AsyncBatchDelivery.class));
builder.withMessageOnly(false);
IndexNameFormatter indexNameFormatter = mock(IndexNameFormatter.class);
when(indexNameFormatter.format(any(LogEvent.class))).thenReturn("testIndexName");
builder.withIndexNameFormatter(indexNameFormatter);
return builder;
}
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:15,代码来源:ElasticsearchAppenderTest.java
示例8: validate
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
private void validate(final Configuration config) {
assertNotNull(config);
assertNotNull(config.getName());
assertFalse(config.getName().isEmpty());
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 2);
final KafkaAppender kafkaAppender = (KafkaAppender) appenders.get("Kafka");
final GelfLayout gelfLayout = (GelfLayout) kafkaAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final LoggerConfig rootLoggerConfig = loggers.get("");
assertEquals(Level.ERROR, rootLoggerConfig.getLevel());
assertFalse(rootLoggerConfig.isIncludeLocation());
final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j");
assertEquals(Level.DEBUG, loggerConfig.getLevel());
assertTrue(loggerConfig.isIncludeLocation());
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final List<CustomLevelConfig> customLevels = config.getCustomLevels();
assertNotNull("No CustomLevels", filter);
assertEquals(1, customLevels.size());
final CustomLevelConfig customLevel = customLevels.get(0);
assertEquals("Panic", customLevel.getLevelName());
assertEquals(17, customLevel.getIntLevel());
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:33,代码来源:ConfigurationAssemblerTest.java
示例9: validate
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
private void validate(final Configuration config) {
assertNotNull(config);
assertNotNull(config.getName());
assertFalse(config.getName().isEmpty());
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final ConsoleAppender consoleAppender = (ConsoleAppender)appenders.get("Stdout");
final PatternLayout gelfLayout = (PatternLayout)consoleAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final LoggerConfig rootLoggerConfig = loggers.get("");
assertEquals(Level.ERROR, rootLoggerConfig.getLevel());
assertFalse(rootLoggerConfig.isIncludeLocation());
final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j");
assertEquals(Level.DEBUG, loggerConfig.getLevel());
assertTrue(loggerConfig.isIncludeLocation());
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final List<CustomLevelConfig> customLevels = config.getCustomLevels();
assertNotNull("No CustomLevels", filter);
assertEquals(1, customLevels.size());
final CustomLevelConfig customLevel = customLevels.get(0);
assertEquals("Panic", customLevel.getLevelName());
assertEquals(17, customLevel.getIntLevel());
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:33,代码来源:ConfigurationAssemblerTest.java
示例10: 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
示例11: 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
示例12: appenderUsesThresholdFilter
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
@Test
public void appenderUsesThresholdFilter() throws Exception {
assertThat(appender.getFilter()).isInstanceOf(ThresholdFilter.class);
}
开发者ID:graylog-labs,项目名称:graylog-plugin-internal-logs,代码行数:5,代码来源:DirectConsumingAppenderTest.java
示例13: Log4j2Appender
import org.apache.logging.log4j.core.filter.ThresholdFilter; //导入依赖的package包/类
Log4j2Appender(Log4j2Watcher watcher, ThresholdFilter filter, Level threshold) {
super("Log4j2WatcherAppender", filter, null);
this.watcher = watcher;
this.filter = filter;
this.threshold = threshold;
}
开发者ID:lucidworks,项目名称:solr-log4j2,代码行数:7,代码来源:Log4j2Watcher.java
示例14: 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
示例15: 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
示例16: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论