use of org.apache.log4j.spi.Filter in project logging-log4j2 by apache.
the class FilterAdapter method filter.
@Override
public Result filter(LogEvent event) {
LoggingEvent loggingEvent = new LogEventAdapter(event);
Filter next = filter;
while (next != null) {
switch(filter.decide(loggingEvent)) {
case Filter.ACCEPT:
return Result.ACCEPT;
case Filter.DENY:
return Result.DENY;
default:
}
next = filter.getNext();
}
return Result.NEUTRAL;
}
use of org.apache.log4j.spi.Filter in project logging-log4j2 by apache.
the class LevelMatchFilterBuilder method createFilter.
private Filter createFilter(String level, boolean acceptOnMatch) {
Level lvl = Level.ERROR;
if (level != null) {
lvl = Level.toLevel(level, Level.ERROR);
}
org.apache.logging.log4j.core.Filter.Result onMatch = acceptOnMatch ? org.apache.logging.log4j.core.Filter.Result.ACCEPT : org.apache.logging.log4j.core.Filter.Result.DENY;
return new FilterWrapper(LevelMatchFilter.newBuilder().setLevel(lvl).setOnMatch(onMatch).setOnMismatch(org.apache.logging.log4j.core.Filter.Result.NEUTRAL).build());
}
use of org.apache.log4j.spi.Filter in project logging-log4j2 by apache.
the class SyslogAppenderBuilder method parseAppender.
@Override
public Appender parseAppender(final String name, final String appenderPrefix, final String layoutPrefix, final String filterPrefix, final Properties props, final PropertiesConfiguration configuration) {
Filter filter = configuration.parseAppenderFilters(props, filterPrefix, name);
Layout layout = configuration.parseLayout(layoutPrefix, name, props);
String level = getProperty(THRESHOLD_PARAM);
String facility = getProperty(FACILITY_PARAM, DEFAULT_FACILITY);
String syslogHost = getProperty(SYSLOG_HOST_PARAM, DEFAULT_HOST + ":" + DEFAULT_PORT);
String protocol = getProperty(PROTOCOL_PARAM, Protocol.TCP.name());
return createAppender(name, configuration, layout, facility, filter, syslogHost, level, Protocol.valueOf(protocol));
}
use of org.apache.log4j.spi.Filter in project xtext-core by eclipse.
the class LoggingTester method removeFilter.
private static void removeFilter(Appender appender, Filter filter) {
if (Objects.equals(appender.getFilter(), filter)) {
appender.clearFilters();
appender.addFilter(filter.getNext());
} else {
for (Filter current = appender.getFilter(); current != null; current = current.getNext()) {
if (Objects.equals(current.getNext(), filter)) {
current.setNext(filter.getNext());
return;
}
}
}
}
use of org.apache.log4j.spi.Filter in project knime-core by knime.
the class NodeLogger method updateLog4JKNIMELoggerLevel.
/**
* Adjusts log level of 'knime' loggers so that it matches the minimum level of all registered appenders.
* Called after initialization and after the log level is changed for individual appenders.
*/
private static void updateLog4JKNIMELoggerLevel() {
final Logger rootLogger = LogManager.getRootLogger();
// by default this is 'ERROR' but may be changed in log4j.xml
Level minimumLevel = rootLogger.getLevel();
for (@SuppressWarnings("unchecked") Enumeration<Appender> appenderEnum = rootLogger.getAllAppenders(); appenderEnum.hasMoreElements(); ) {
Appender next = appenderEnum.nextElement();
for (Filter filter = next.getFilter(); filter != null; filter = filter.getNext()) {
Level l = null;
if (filter instanceof LevelMatchFilter) {
l = OptionConverter.toLevel(((LevelMatchFilter) filter).getLevelToMatch(), Level.FATAL);
} else if (filter instanceof LevelRangeFilter) {
l = ((LevelRangeFilter) filter).getLevelMin();
}
if (l != null && minimumLevel.isGreaterOrEqual(l)) {
minimumLevel = l;
}
}
}
final Level minimumLevelFinal = minimumLevel;
synchronized (LOGGERS) {
knownLoggerPrefixes.stream().map(LogManager::getLogger).forEach(l -> l.setLevel(minimumLevelFinal));
}
}
Aggregations