use of com.axway.ats.log.autodb.filters.NoSystemLevelEventsFilter in project ats-framework by Axway.
the class RemoteLoggingConfigurator method apply.
@Override
@SuppressWarnings("unchecked")
public void apply() {
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());
}
}
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();
//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()));
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()));
}
}
}
Aggregations