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);
}
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations