本文整理汇总了Java中org.apache.log4j.Appender.addFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Appender.addFilter方法的具体用法?Java Appender.addFilter怎么用?Java Appender.addFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.Appender
的用法示例。
在下文中一共展示了Appender.addFilter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeFilter
import org.apache.log4j.Appender; //导入方法依赖的package包/类
private static void removeFilter(final Appender appender, final Filter filter) {
Filter _filter = appender.getFilter();
boolean _equals = Objects.equal(_filter, filter);
if (_equals) {
appender.clearFilters();
appender.addFilter(filter.getNext());
} else {
for (Filter current = appender.getFilter(); (current != null); current = current.getNext()) {
Filter _next = current.getNext();
boolean _equals_1 = Objects.equal(_next, filter);
if (_equals_1) {
current.setNext(filter.getNext());
return;
}
}
}
}
示例2: configureLogger
import org.apache.log4j.Appender; //导入方法依赖的package包/类
private synchronized void configureLogger() {
org.apache.log4j.Logger npmLogger = org.apache.log4j.Logger.getLogger(
"com.github.eirslett.maven.plugins.frontend.lib.DefaultYarnRunner");
Enumeration appenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
if (appenders != null) {
while (appenders.hasMoreElements()) {
Appender appender = (Appender) appenders.nextElement();
appender.addFilter(new Filter() {
@Override
public int decide(LoggingEvent loggingEvent) {
if (loggingEvent.getLoggerName().contains("DefaultYarnRunner")) {
return DENY;
} else {
return NEUTRAL;
}
}
});
}
}
npmLogger.addAppender(new WriterAppender(
new PatternLayout("%m%n"),
out
));
}
示例3: setupBeforeClass
import org.apache.log4j.Appender; //导入方法依赖的package包/类
@BeforeClass
public static void setupBeforeClass() throws Exception {
Logger xenqtt = Logger.getLogger("xenqtt");
assertNotNull(xenqtt);
Appender console = Logger.getRootLogger().getAppender("console");
assertNotNull(console);
console.addFilter(new Filter() {
@Override
public int decide(LoggingEvent event) {
entries.add(event.getRenderedMessage());
ThrowableInformation info = event.getThrowableInformation();
if (info != null) {
Throwable t = info.getThrowable();
if (t != null) {
entries.add(t.getMessage());
}
}
return Filter.ACCEPT;
}
});
}
示例4: parseFilters
import org.apache.log4j.Appender; //导入方法依赖的package包/类
/**
Used internally to parse a filter element.
*/
protected
void parseFilters(Element element, Appender appender) {
String clazz = subst(element.getAttribute(CLASS_ATTR));
Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz,
Filter.class, null);
if(filter != null) {
PropertySetter propSetter = new PropertySetter(filter);
NodeList children = element.getChildNodes();
final int length = children.getLength();
for (int loop = 0; loop < length; loop++) {
Node currentNode = children.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element currentElement = (Element) currentNode;
String tagName = currentElement.getTagName();
if(tagName.equals(PARAM_TAG)) {
setParameter(currentElement, propSetter);
} else {
quietParseUnrecognizedElement(filter, currentElement, props);
}
}
}
propSetter.activate();
LogLog.debug("Adding filter of type ["+filter.getClass()
+"] to appender named ["+appender.getName()+"].");
appender.addFilter(filter);
}
}
示例5: accept
import org.apache.log4j.Appender; //导入方法依赖的package包/类
public void accept() throws Exception {
// set up appender
Layout layout = new SimpleLayout();
Appender appender = new FileAppender(layout, ACCEPT_FILE, false);
// create LevelMatchFilter
LevelMatchFilter matchFilter = new LevelMatchFilter();
// attach match filter to appender
appender.addFilter(matchFilter);
// attach DenyAllFilter to end of filter chain to deny neutral
// (non matching) messages
appender.addFilter(new DenyAllFilter());
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.TRACE);
Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN,
Level.ERROR, Level.FATAL};
for (int x = 0; x < levelArray.length; x++) {
// set the level to match
matchFilter.setLevelToMatch(levelArray[x].toString());
common("pass " + x + "; filter set to accept only "
+ levelArray[x].toString() + " msgs");
}
Transformer.transform(ACCEPT_FILE, ACCEPT_FILTERED, new LineNumberFilter());
assertTrue(Compare.compare(ACCEPT_FILTERED, ACCEPT_WITNESS));
}
示例6: deny
import org.apache.log4j.Appender; //导入方法依赖的package包/类
public void deny() throws Exception {
// set up appender
Layout layout = new SimpleLayout();
Appender appender = new FileAppender(layout, DENY_FILE, false);
// create LevelMatchFilter, set to deny matches
LevelMatchFilter matchFilter = new LevelMatchFilter();
matchFilter.setAcceptOnMatch(false);
// attach match filter to appender
appender.addFilter(matchFilter);
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.TRACE);
Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN,
Level.ERROR, Level.FATAL};
for (int x = 0; x < levelArray.length; x++) {
// set the level to match
matchFilter.setLevelToMatch(levelArray[x].toString());
common("pass " + x + "; filter set to deny only " + levelArray[x].toString()
+ " msgs");
}
Transformer.transform(DENY_FILE, DENY_FILTERED, new LineNumberFilter());
assertTrue(Compare.compare(DENY_FILTERED, DENY_WITNESS));
}
示例7: apply
import org.apache.log4j.Appender; //导入方法依赖的package包/类
@Override
@SuppressWarnings( "unchecked")
public void apply() {
/*
* This code is run on remote agent's side
*/
if (needsToConfigureDbAppender) {
//first get all appenders in the root category and apply the filter
//which will deny logging of system events
Logger rootLogger = Logger.getRootLogger();
Enumeration<Appender> appenders = rootLogger.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
if (! (appender instanceof AbstractDbAppender)) {
// apply this filter on all appenders which are not coming from ATS
appender.addFilter(new NoSystemLevelEventsFilter());
}
}
//attach the appender to the logging system
Category log;
if ("root".equals(appenderLogger)) {
log = Logger.getRootLogger();
} else {
log = Logger.getLogger(appenderLogger);
}
log.setLevel(Level.toLevel(appenderConfiguration.getLoggingThreshold().toInt()));
final String caller = ThreadsPerCaller.getCaller();
//create the new appender
PassiveDbAppender attachedAppender = new PassiveDbAppender(caller);
attachedAppender.setAppenderConfig(appenderConfiguration);
//use a default pattern, as we log in the db
attachedAppender.setLayout(new PatternLayout("%c{2}: %m%n"));
attachedAppender.activateOptions();
log.addAppender(attachedAppender);
}
if (needsToConfigureUserLoggers) {
for (Entry<String, Integer> userLogger : otherLoggerLevels.entrySet()) {
/*
* We want to set the level of this logger.
* It is not important if this logger is already attached to log4j system or
* not as the next code will obtain it(in case logger exists) or will create it
* and then will set its level
*/
Logger.getLogger(userLogger.getKey())
.setLevel(Level.toLevel(userLogger.getValue()));
}
}
}
示例8: createConsoleAppender
import org.apache.log4j.Appender; //导入方法依赖的package包/类
/**
* Creates console appender with some reasonable default logging settings.
*
* @param maxLevel Max logging level.
* @return New console appender.
*/
private Appender createConsoleAppender(Level maxLevel) {
String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
// Configure output that should go to System.out
Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.TRACE);
lvlFilter.setLevelMax(maxLevel);
app.addFilter(lvlFilter);
return app;
}