Search in sources :

Example 56 with Appender

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);
        }
    }
}
Also used : Appender(org.apache.log4j.Appender) RollingFileAppender(org.apache.log4j.RollingFileAppender) Enumeration(java.util.Enumeration) Filter(org.apache.log4j.spi.Filter)

Example 57 with Appender

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;
}
Also used : ActiveDbAppender(com.axway.ats.log.appenders.ActiveDbAppender) PassiveDbAppender(com.axway.ats.log.appenders.PassiveDbAppender) Appender(org.apache.log4j.Appender) ActiveDbAppender(com.axway.ats.log.appenders.ActiveDbAppender) GetCurrentTestCaseEvent(com.axway.ats.log.autodb.events.GetCurrentTestCaseEvent) PassiveDbAppender(com.axway.ats.log.appenders.PassiveDbAppender)

Example 58 with Appender

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);
}
Also used : Appender(org.apache.log4j.Appender) Logger(org.apache.log4j.Logger)

Example 59 with Appender

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."));
}
Also used : WriterAppender(org.apache.log4j.WriterAppender) Appender(org.apache.log4j.Appender) SimpleLayout(org.apache.log4j.SimpleLayout) SimpleLayout(org.apache.log4j.SimpleLayout) Layout(org.apache.log4j.Layout) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriterAppender(org.apache.log4j.WriterAppender) Logger(org.apache.log4j.Logger) Test(org.junit.Test)

Example 60 with Appender

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));
}
Also used : Appender(org.apache.log4j.Appender) RollingFileAppender(org.apache.log4j.RollingFileAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender)

Aggregations

Appender (org.apache.log4j.Appender)73 FileAppender (org.apache.log4j.FileAppender)24 Logger (org.apache.log4j.Logger)20 File (java.io.File)12 ConsoleAppender (org.apache.log4j.ConsoleAppender)11 RollingFileAppender (org.apache.log4j.RollingFileAppender)11 WriterAppender (org.apache.log4j.WriterAppender)11 NullAppender (org.apache.log4j.varia.NullAppender)11 PatternLayout (org.apache.log4j.PatternLayout)9 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)8 Enumeration (java.util.Enumeration)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 AsyncAppender (org.apache.log4j.AsyncAppender)6 Layout (org.apache.log4j.Layout)6 LogfileAppender (org.knime.core.util.LogfileAppender)6 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)5 Filter (org.apache.log4j.spi.Filter)5 LevelRangeFilter (org.apache.log4j.varia.LevelRangeFilter)5 ActiveDbAppender (com.axway.ats.log.appenders.ActiveDbAppender)4