use of org.apache.log4j.Appender 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 org.apache.log4j.Appender in project zm-mailbox by Zimbra.
the class PlaybackUtil method setup.
private static void setup() throws ServiceException {
// set up log4j
ZimbraLog.toolSetupLog4j("INFO", LC.zimbra_log4j_properties.value());
// remove the console appender if any
Logger rootLogger = Logger.getRootLogger();
Appender consoleAppender = null;
Enumeration appenders = rootLogger.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = (Appender) appenders.nextElement();
if (appender instanceof ConsoleAppender) {
consoleAppender = appender;
}
}
if (consoleAppender != null)
rootLogger.removeAppender(consoleAppender);
DbPool.startup();
Zimbra.startupCLI();
}
use of org.apache.log4j.Appender in project apex-core by apache.
the class ApexCli method preImpersonationInit.
public void preImpersonationInit(String[] args) throws IOException {
Signal.handle(new Signal("INT"), new SignalHandler() {
@Override
public void handle(Signal sig) {
System.out.println("^C");
if (commandThread != null) {
commandThread.interrupt();
mainThread.interrupt();
} else {
System.out.print(prompt);
System.out.flush();
}
}
});
consolePresent = (System.console() != null);
Options options = new Options();
options.addOption("e", true, "Commands are read from the argument");
options.addOption("v", false, "Verbose mode level 1");
options.addOption("vv", false, "Verbose mode level 2");
options.addOption("vvv", false, "Verbose mode level 3");
options.addOption("vvvv", false, "Verbose mode level 4");
options.addOption("r", false, "JSON Raw mode");
options.addOption("p", true, "JSONP padding function");
options.addOption("h", false, "Print this help");
options.addOption("f", true, "Use the specified prompt at all time");
options.addOption("kp", true, "Use the specified kerberos principal");
options.addOption("kt", true, "Use the specified kerberos keytab");
CommandLineParser parser = new BasicParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("v")) {
verboseLevel = 1;
}
if (cmd.hasOption("vv")) {
verboseLevel = 2;
}
if (cmd.hasOption("vvv")) {
verboseLevel = 3;
}
if (cmd.hasOption("vvvv")) {
verboseLevel = 4;
}
if (cmd.hasOption("r")) {
raw = true;
}
if (cmd.hasOption("e")) {
commandsToExecute = cmd.getOptionValues("e");
consolePresent = false;
}
if (cmd.hasOption("p")) {
jsonp = cmd.getOptionValue("p");
}
if (cmd.hasOption("f")) {
forcePrompt = cmd.getOptionValue("f");
}
if (cmd.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(ApexCli.class.getSimpleName(), options);
System.exit(0);
}
if (cmd.hasOption("kp")) {
kerberosPrincipal = cmd.getOptionValue("kp");
}
if (cmd.hasOption("kt")) {
kerberosKeyTab = cmd.getOptionValue("kt");
}
} catch (ParseException ex) {
System.err.println("Invalid argument: " + ex);
System.exit(1);
}
if (kerberosPrincipal == null && kerberosKeyTab != null) {
System.err.println("Kerberos key tab is specified but not the kerberos principal. Please specify it using the -kp option.");
System.exit(1);
}
if (kerberosPrincipal != null && kerberosKeyTab == null) {
System.err.println("Kerberos principal is specified but not the kerberos key tab. Please specify it using the -kt option.");
System.exit(1);
}
Level logLevel;
switch(verboseLevel) {
case 0:
logLevel = Level.OFF;
break;
case 1:
logLevel = Level.ERROR;
break;
case 2:
logLevel = Level.WARN;
break;
case 3:
logLevel = Level.INFO;
break;
default:
logLevel = Level.DEBUG;
break;
}
for (org.apache.log4j.Logger logger : new org.apache.log4j.Logger[] { org.apache.log4j.Logger.getRootLogger(), org.apache.log4j.Logger.getLogger(ApexCli.class) }) {
/*
* Override logLevel specified by user, the same logLevel would be inherited by all
* appenders related to logger.
*/
logger.setLevel(logLevel);
@SuppressWarnings("unchecked") Enumeration<Appender> allAppenders = logger.getAllAppenders();
while (allAppenders.hasMoreElements()) {
Appender appender = allAppenders.nextElement();
if (appender instanceof ConsoleAppender) {
((ConsoleAppender) appender).setThreshold(logLevel);
}
}
}
if (commandsToExecute != null) {
for (String command : commandsToExecute) {
LOG.debug("Command to be executed: {}", command);
}
}
if (kerberosPrincipal != null && kerberosKeyTab != null) {
StramUserLogin.authenticate(kerberosPrincipal, kerberosKeyTab);
} else {
Configuration config = new YarnConfiguration();
StramClientUtils.addDTLocalResources(config);
StramUserLogin.attemptAuthentication(config);
}
}
use of org.apache.log4j.Appender in project apex-core by apache.
the class LoggerUtil method getFileAppender.
private static FileAppender getFileAppender() {
Enumeration<Appender> e = LogManager.getRootLogger().getAllAppenders();
FileAppender fileAppender = null;
while (e.hasMoreElements()) {
Appender appender = e.nextElement();
if (appender instanceof FileAppender) {
if (fileAppender == null) {
fileAppender = (FileAppender) appender;
} else {
//skip fetching log file information if we have multiple file Appenders
return null;
}
}
}
return fileAppender;
}
use of org.apache.log4j.Appender in project apex-core by apache.
the class LoggerUtil method addAppender.
/**
* Adds Logger Appender
* @param name Appender name
* @param properties Appender properties
* @return True if the appender has been added successfully
*/
public static boolean addAppender(String name, Properties properties) {
if (getAppendersNames().contains(name)) {
logger.warn("A logger appender with the name '{}' exists. Cannot add a new logger appender with the same name", name);
} else {
try {
Method method = PropertyConfigurator.class.getDeclaredMethod("parseAppender", Properties.class, String.class);
method.setAccessible(true);
Appender appender = (Appender) method.invoke(new PropertyConfigurator(), properties, name);
if (appender == null) {
logger.warn("Cannot add a new logger appender. Name: {}, Properties: {}", name, properties);
} else {
LogManager.getRootLogger().addAppender(appender);
return true;
}
} catch (Exception ex) {
logger.warn("Cannot add a new logger appender. Name: {}, Properties: {}", name, properties, ex);
}
}
return false;
}
Aggregations