Search in sources :

Example 46 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 47 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 48 with Appender

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()));
        }
    }
}
Also used : ActiveDbAppender(com.axway.ats.log.appenders.ActiveDbAppender) PassiveDbAppender(com.axway.ats.log.appenders.PassiveDbAppender) Appender(org.apache.log4j.Appender) AbstractDbAppender(com.axway.ats.log.appenders.AbstractDbAppender) NoSystemLevelEventsFilter(com.axway.ats.log.autodb.filters.NoSystemLevelEventsFilter) Category(org.apache.log4j.Category) PatternLayout(org.apache.log4j.PatternLayout) AbstractDbAppender(com.axway.ats.log.appenders.AbstractDbAppender) Logger(org.apache.log4j.Logger) PassiveDbAppender(com.axway.ats.log.appenders.PassiveDbAppender)

Example 49 with Appender

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);
        }
    }
}
Also used : DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) Appender(org.apache.log4j.Appender) IOException(java.io.IOException) CoreVoltLogger(org.voltcore.logging.VoltLogger.CoreVoltLogger) Logger(org.apache.log4j.Logger) File(java.io.File) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender)

Example 50 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)54 FileAppender (org.apache.log4j.FileAppender)17 Logger (org.apache.log4j.Logger)15 File (java.io.File)13 ConsoleAppender (org.apache.log4j.ConsoleAppender)11 RollingFileAppender (org.apache.log4j.RollingFileAppender)11 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)8 Enumeration (java.util.Enumeration)7 AsyncAppender (org.apache.log4j.AsyncAppender)6 PatternLayout (org.apache.log4j.PatternLayout)6 IOException (java.io.IOException)5 ActiveDbAppender (com.axway.ats.log.appenders.ActiveDbAppender)4 PassiveDbAppender (com.axway.ats.log.appenders.PassiveDbAppender)4 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 Category (org.apache.log4j.Category)4 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)4 Layout (org.apache.log4j.Layout)4