use of org.apache.log4j.Appender in project gocd by gocd.
the class LoggingHelper method addConsoleNDCLogRemoverFilter.
private static void addConsoleNDCLogRemoverFilter() {
Enumeration allAppenders = Logger.getRootLogger().getAllAppenders();
while (allAppenders.hasMoreElements()) {
Appender appender = (Appender) allAppenders.nextElement();
if (isConsoleNdcAppender(appender)) {
continue;
}
Filter filter = getConsoleNDCFilter(appender);
if (filter != CONSOLE_NDC_REJECT_FILTER) {
appender.addFilter(CONSOLE_NDC_REJECT_FILTER);
}
}
}
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 hadoop by apache.
the class TaskLog method syncLogs.
@SuppressWarnings("unchecked")
public static synchronized void syncLogs(String logLocation, TaskAttemptID taskid, boolean isCleanup) throws IOException {
System.out.flush();
System.err.flush();
Enumeration<Logger> allLoggers = LogManager.getCurrentLoggers();
while (allLoggers.hasMoreElements()) {
Logger l = allLoggers.nextElement();
Enumeration<Appender> allAppenders = l.getAllAppenders();
while (allAppenders.hasMoreElements()) {
Appender a = allAppenders.nextElement();
if (a instanceof TaskLogAppender) {
((TaskLogAppender) a).flush();
}
}
}
if (currentTaskid != taskid) {
currentTaskid = taskid;
resetPrevLengths(logLocation);
}
writeToIndexFile(logLocation, isCleanup);
}
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 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