use of com.axway.ats.log.appenders.PassiveDbAppender in project ats-framework by Axway.
the class RemoteLoggingConfigurator method needsApplying.
@Override
@SuppressWarnings("unchecked")
public boolean needsApplying() {
/*
* This code is run on remote agent's side
*/
final String caller = ThreadsPerCaller.getCaller();
needsToConfigureDbAppender = false;
if (appenderConfiguration != null) {
PassiveDbAppender dbAppender = PassiveDbAppender.getCurrentInstance(caller);
if (dbAppender == null || !dbAppender.getAppenderConfig().equals(appenderConfiguration)) {
// we did not have a DB appender
// or the DB appender configuration is changed
needsToConfigureDbAppender = true;
}
}
needsToConfigureUserLoggers = false;
for (Entry<String, Integer> userLogger : otherLoggerLevels.entrySet()) {
Enumeration<Logger> allLoggers = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();
boolean loggerAlreadyExists = false;
boolean loggerLevelIsDifferent = false;
while (allLoggers.hasMoreElements()) {
Logger logger = allLoggers.nextElement();
if (logger.getName().equals(userLogger.getKey())) {
// this logger is already available, check its level
loggerAlreadyExists = true;
if (logger.getLevel() == null || logger.getLevel().toInt() != userLogger.getValue()) {
// logger level is not set or it is not correct
loggerLevelIsDifferent = true;
}
break;
}
}
if (!loggerAlreadyExists || loggerLevelIsDifferent) {
// there is at lease one logger that must be reconfigured
needsToConfigureUserLoggers = true;
break;
}
}
return needsToConfigureDbAppender || needsToConfigureUserLoggers;
}
use of com.axway.ats.log.appenders.PassiveDbAppender in project ats-framework by Axway.
the class AtsDbLogger method getCurrentTestCaseState.
/**
* This event can not go through the regular way of sending log4j events in the case with Passive DB appenders.
* The reason is that we have to evaluate the result after the work of each passive appender and stop
* calling these appenders when the first one(the only one serving this caller) has processed the event.
*/
@SuppressWarnings("unchecked")
public TestCaseState getCurrentTestCaseState() {
GetCurrentTestCaseEvent event = new GetCurrentTestCaseEvent(ATS_DB_LOGGER_CLASS_NAME, logger);
Enumeration<Appender> appenders = Logger.getRootLogger().getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
if (appender instanceof ActiveDbAppender) {
// Comes here on Test Executor side. There is just 1 Active appender
return ((ActiveDbAppender) appender).getCurrentTestCaseState(event).getTestCaseState();
} else if (appender instanceof PassiveDbAppender) {
// Comes here on Agent side. There will be 1 Passive appender per caller
// Pass the event to any existing appender.
// The correct one will return result, wrong appenders will return null.
GetCurrentTestCaseEvent resultEvent = ((PassiveDbAppender) appender).getCurrentTestCaseState(event);
if (resultEvent != null) {
// we found the right Passive appender
return resultEvent.getTestCaseState();
}
}
}
// no appropriate appender found
return null;
}
use of com.axway.ats.log.appenders.PassiveDbAppender in project ats-framework by Axway.
the class AgentWsImpl method getNumberPendingLogEvents.
@WebMethod
public synchronized int getNumberPendingLogEvents() throws AgentException {
final String caller = getCaller();
ThreadsPerCaller.registerThread(caller);
try {
PassiveDbAppender appender = PassiveDbAppender.getCurrentInstance(caller);
if (appender != null) {
return appender.getNumberPendingLogEvents();
}
} finally {
ThreadsPerCaller.unregisterThread();
}
return -1;
}
use of com.axway.ats.log.appenders.PassiveDbAppender in project ats-framework by Axway.
the class AutoLogger method getCurrentTestCaseState.
/**
* This event can not go through the regular way of sending log4j events in the case with Passive DB appenders.
* The reason is that we have to evaluate the result after the work of each passive appender and stop
* calling these appenders when the first one(the only one serving this caller) has processed the event.
*/
@SuppressWarnings("unchecked")
public TestCaseState getCurrentTestCaseState() {
GetCurrentTestCaseEvent event = new GetCurrentTestCaseEvent(AUTO_LOGGER_CLASS_NAME, logger);
Enumeration<Appender> appenders = Logger.getRootLogger().getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
if (appender instanceof ActiveDbAppender) {
// Comes here on Test Executor side. There is just 1 Active appender
return ((ActiveDbAppender) appender).getCurrentTestCaseState(event).getTestCaseState();
} else if (appender instanceof PassiveDbAppender) {
// Comes here on Agent side. There will be 1 Passive appender per caller
// Pass the event to any existing appender.
// The correct one will return result, wrong appenders will return null.
GetCurrentTestCaseEvent resultEvent = ((PassiveDbAppender) appender).getCurrentTestCaseState(event);
if (resultEvent != null) {
// we found the right Passive appender
return resultEvent.getTestCaseState();
}
}
}
// no appropriate appender found
return null;
}
use of com.axway.ats.log.appenders.PassiveDbAppender 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