Search in sources :

Example 1 with AsyncAppender

use of org.apache.log4j.AsyncAppender in project hadoop by apache.

the class FSNamesystem method enableAsyncAuditLog.

private static void enableAsyncAuditLog() {
    if (!(auditLog instanceof Log4JLogger)) {
        LOG.warn("Log4j is required to enable async auditlog");
        return;
    }
    Logger logger = ((Log4JLogger) auditLog).getLogger();
    @SuppressWarnings("unchecked") List<Appender> appenders = Collections.list(logger.getAllAppenders());
    // failsafe against trying to async it more than once
    if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
        AsyncAppender asyncAppender = new AsyncAppender();
        // previously configured appenders
        for (Appender appender : appenders) {
            logger.removeAppender(appender);
            asyncAppender.addAppender(appender);
        }
        logger.addAppender(asyncAppender);
    }
}
Also used : AsyncAppender(org.apache.log4j.AsyncAppender) Appender(org.apache.log4j.Appender) AsyncAppender(org.apache.log4j.AsyncAppender) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) TopAuditLogger(org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger) Logger(org.apache.log4j.Logger) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger)

Example 2 with AsyncAppender

use of org.apache.log4j.AsyncAppender in project hadoop by apache.

the class TestAuditLogs method setupCluster.

@Before
public void setupCluster() throws Exception {
    // must configure prior to instantiating the namesystem because it
    // will reconfigure the logger if async is enabled
    configureAuditLogs();
    conf = new HdfsConfiguration();
    final long precision = 1L;
    conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
    conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_EDITS_ASYNC_LOGGING, useAsyncEdits);
    util = new DFSTestUtil.Builder().setName("TestAuditAllowed").setNumFiles(20).build();
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
    fs = cluster.getFileSystem();
    util.createFiles(fs, fileName);
    // make sure the appender is what it's supposed to be
    Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
    @SuppressWarnings("unchecked") List<Appender> appenders = Collections.list(logger.getAllAppenders());
    assertEquals(1, appenders.size());
    assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);
    fnames = util.getFileNames(fileName);
    util.waitReplication(fs, fileName, (short) 3);
    userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
Also used : Appender(org.apache.log4j.Appender) AsyncAppender(org.apache.log4j.AsyncAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) AsyncAppender(org.apache.log4j.AsyncAppender) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) Logger(org.apache.log4j.Logger) Before(org.junit.Before)

Example 3 with AsyncAppender

use of org.apache.log4j.AsyncAppender in project hadoop by apache.

the class MetricsLoggerTask method makeMetricsLoggerAsync.

/**
   * Make the metrics logger async and add all pre-existing appenders to the
   * async appender.
   */
public static void makeMetricsLoggerAsync(Log metricsLog) {
    if (!(metricsLog instanceof Log4JLogger)) {
        LOG.warn("Metrics logging will not be async since " + "the logger is not log4j");
        return;
    }
    org.apache.log4j.Logger logger = ((Log4JLogger) metricsLog).getLogger();
    // Don't pollute actual logs with metrics dump
    logger.setAdditivity(false);
    @SuppressWarnings("unchecked") List<Appender> appenders = Collections.list(logger.getAllAppenders());
    // failsafe against trying to async it more than once
    if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
        AsyncAppender asyncAppender = new AsyncAppender();
        // previously configured appenders
        for (Appender appender : appenders) {
            logger.removeAppender(appender);
            asyncAppender.addAppender(appender);
        }
        logger.addAppender(asyncAppender);
    }
}
Also used : Appender(org.apache.log4j.Appender) AsyncAppender(org.apache.log4j.AsyncAppender) AsyncAppender(org.apache.log4j.AsyncAppender) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger)

Example 4 with AsyncAppender

use of org.apache.log4j.AsyncAppender in project gerrit by GerritCodeReview.

the class SystemLog method createAsyncAppender.

public AsyncAppender createAsyncAppender(String name, Layout layout) {
    AsyncAppender async = new AsyncAppender();
    async.setName(name);
    async.setBlocking(true);
    async.setBufferSize(config.getInt("core", "asyncLoggingBufferSize", 64));
    async.setLocationInfo(false);
    if (shouldConfigure()) {
        async.addAppender(createAppender(site.logs_dir, name, layout));
    } else {
        Appender appender = LogManager.getLogger(name).getAppender(name);
        if (appender != null) {
            async.addAppender(appender);
        } else {
            log.warn("No appender with the name: " + name + " was found. " + name + " logging is disabled");
        }
    }
    async.activateOptions();
    return async;
}
Also used : DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) Appender(org.apache.log4j.Appender) AsyncAppender(org.apache.log4j.AsyncAppender) AsyncAppender(org.apache.log4j.AsyncAppender)

Example 5 with AsyncAppender

use of org.apache.log4j.AsyncAppender in project gerrit by GerritCodeReview.

the class PluginLogFile method start.

@Override
public void start() {
    AsyncAppender asyncAppender = systemLog.createAsyncAppender(logName, layout);
    Logger logger = LogManager.getLogger(logName);
    logger.removeAppender(logName);
    logger.addAppender(asyncAppender);
    logger.setAdditivity(false);
}
Also used : AsyncAppender(org.apache.log4j.AsyncAppender) Logger(org.apache.log4j.Logger)

Aggregations

AsyncAppender (org.apache.log4j.AsyncAppender)5 Appender (org.apache.log4j.Appender)4 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)3 Logger (org.apache.log4j.Logger)3 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 TopAuditLogger (org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger)1 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)1 RollingFileAppender (org.apache.log4j.RollingFileAppender)1 Before (org.junit.Before)1