use of org.apache.log4j.Appender in project hadoop by apache.
the class TestYARNRunner method testWarnCommandOpts.
@Test(timeout = 20000)
public void testWarnCommandOpts() throws Exception {
Logger logger = Logger.getLogger(YARNRunner.class);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, bout);
logger.addAppender(appender);
JobConf jobConf = new JobConf();
jobConf.set(MRJobConfig.MR_AM_ADMIN_COMMAND_OPTS, "-Djava.net.preferIPv4Stack=true -Djava.library.path=foo");
jobConf.set(MRJobConfig.MR_AM_COMMAND_OPTS, "-Xmx1024m -Djava.library.path=bar");
YARNRunner yarnRunner = new YARNRunner(jobConf);
@SuppressWarnings("unused") ApplicationSubmissionContext submissionContext = buildSubmitContext(yarnRunner, jobConf);
String logMsg = bout.toString();
assertTrue(logMsg.contains("WARN - Usage of -Djava.library.path in " + "yarn.app.mapreduce.am.admin-command-opts can cause programs to no " + "longer function if hadoop native libraries are used. These values " + "should be set as part of the LD_LIBRARY_PATH in the app master JVM " + "env using yarn.app.mapreduce.am.admin.user.env config settings."));
assertTrue(logMsg.contains("WARN - Usage of -Djava.library.path in " + "yarn.app.mapreduce.am.command-opts can cause programs to no longer " + "function if hadoop native libraries are used. These values should " + "be set as part of the LD_LIBRARY_PATH in the app master JVM env " + "using yarn.app.mapreduce.am.env config settings."));
}
use of org.apache.log4j.Appender 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 org.apache.log4j.Appender 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()));
}
}
}
use of org.apache.log4j.Appender in project voltdb by VoltDB.
the class VoltLog4jLogger method setFileLoggerRoot.
/**
* Static method to change the log directory root
* @param logRootDH log directory root
*/
public static void setFileLoggerRoot(File logRootDH) {
if (System.getProperty("log4j.configuration", "").toLowerCase().contains("/voltdb/tests/")) {
return;
}
if (Boolean.parseBoolean(System.getProperty("DISABLE_LOG_RECONFIGURE", "false"))) {
return;
}
checkArgument(logRootDH != null, "log root directory is null");
File logDH = new File(logRootDH, "log");
File napFH = new File(logDH, "volt.log");
Logger rootLogger = LogManager.getRootLogger();
DailyRollingFileAppender oap = null;
@SuppressWarnings("unchecked") Enumeration<Appender> appen = rootLogger.getAllAppenders();
while (appen.hasMoreElements()) {
Appender appndr = appen.nextElement();
if (!(appndr instanceof DailyRollingFileAppender))
continue;
oap = (DailyRollingFileAppender) appndr;
File logFH = new File(oap.getFile());
if (!logFH.isAbsolute())
break;
oap = null;
}
if (oap == null) {
return;
}
DailyRollingFileAppender nap = null;
try {
if (!logDH.exists() && !logDH.mkdirs()) {
throw new IllegalArgumentException("failed to create directory " + logDH);
}
if (!logDH.isDirectory() || !logDH.canRead() || !logDH.canWrite() || !logDH.canExecute()) {
throw new IllegalArgumentException("Cannot access " + logDH);
}
nap = new DailyRollingFileAppender(oap.getLayout(), napFH.getPath(), oap.getDatePattern());
} catch (IOException e) {
throw new IllegalArgumentException("Failed to instantiate a DailyRollingFileAppender for file " + napFH, e);
}
nap.setName(oap.getName());
rootLogger.removeAppender(oap.getName());
rootLogger.addAppender(nap);
File oldFH = new File(oap.getFile());
if (oldFH.exists() && oldFH.isFile() && oldFH.length() == 0L && oldFH.delete()) {
File oldDH = oldFH.getParentFile();
if (oldDH.list().length == 0) {
oldDH.delete();
}
}
@SuppressWarnings("unchecked") Enumeration<Logger> e = LogManager.getCurrentLoggers();
while (e.hasMoreElements()) {
Logger lgr = e.nextElement();
Appender apndr = lgr.getAppender(oap.getName());
if (apndr != null) {
lgr.removeAppender(oap.getName());
lgr.addAppender(nap);
}
}
}
use of org.apache.log4j.Appender in project apex-core by apache.
the class StdOutErrLog method tieSystemOutAndErrToLog.
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void tieSystemOutAndErrToLog() {
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
Appender appender = rootLogger.getAppender(DT_LOG_APPENDER);
if (appender instanceof RollingFileAppender) {
RollingFileAppender rfa = (RollingFileAppender) appender;
if (rfa.getFile() == null || rfa.getFile().isEmpty()) {
rfa.setFile(System.getProperty(DT_LOGDIR));
rfa.activateOptions();
}
} else if (appender != null) {
logger.warn("found appender {} instead of RollingFileAppender", appender);
}
LoggerUtil.addAppenders();
System.setOut(createLoggingProxy(System.out));
System.setErr(createLoggingProxy(System.err));
}
Aggregations