use of org.apache.log4j.DailyRollingFileAppender in project hadoop by apache.
the class FairSchedulerEventLog method init.
boolean init(FairSchedulerConfiguration conf) {
if (conf.isEventLogEnabled()) {
try {
logDir = conf.getEventlogDir();
File logDirFile = new File(logDir);
if (!logDirFile.exists()) {
if (!logDirFile.mkdirs()) {
throw new IOException("Mkdirs failed to create " + logDirFile.toString());
}
}
String username = System.getProperty("user.name");
logFile = String.format("%s%shadoop-%s-fairscheduler.log", logDir, File.separator, username);
logDisabled = false;
PatternLayout layout = new PatternLayout("%d{ISO8601}\t%m%n");
appender = new DailyRollingFileAppender(layout, logFile, "'.'yyyy-MM-dd");
appender.activateOptions();
LOG.info("Initialized fair scheduler event log, logging to " + logFile);
} catch (IOException e) {
LOG.error("Failed to initialize fair scheduler event log. Disabling it.", e);
logDisabled = true;
}
} else {
logDisabled = true;
}
return !(logDisabled);
}
use of org.apache.log4j.DailyRollingFileAppender in project voltdb by VoltDB.
the class RealVoltDB method scheduleDailyLoggingWorkInNextCheckTime.
/**
* Get the next check time for a private member in log4j library, which is not a reliable idea.
* It adds 30 seconds for the initial delay and uses a periodical thread to schedule the daily logging work
* with this delay.
* @return
*/
void scheduleDailyLoggingWorkInNextCheckTime() {
DailyRollingFileAppender dailyAppender = null;
Enumeration<?> appenders = Logger.getRootLogger().getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = (Appender) appenders.nextElement();
if (appender instanceof DailyRollingFileAppender) {
dailyAppender = (DailyRollingFileAppender) appender;
}
}
final DailyRollingFileAppender dailyRollingFileAppender = dailyAppender;
Field field = null;
if (dailyRollingFileAppender != null) {
try {
field = dailyRollingFileAppender.getClass().getDeclaredField("nextCheck");
field.setAccessible(true);
} catch (NoSuchFieldException e) {
hostLog.error("Failed to set daily system info logging: " + e.getMessage());
}
}
final Field nextCheckField = field;
long nextCheck = System.currentTimeMillis();
// the next part may throw exception, current time is the default value
if (dailyRollingFileAppender != null && nextCheckField != null) {
try {
nextCheck = nextCheckField.getLong(dailyRollingFileAppender);
scheduleWork(new DailyLogTask(), nextCheck - System.currentTimeMillis() + 30 * 1000, 0, TimeUnit.MILLISECONDS);
} catch (Exception e) {
hostLog.error("Failed to set daily system info logging: " + e.getMessage());
}
}
}
use of org.apache.log4j.DailyRollingFileAppender in project atlas by apache.
the class FailedMessagesLogger method init.
void init() {
String rootLoggerDirectory = getRootLoggerDirectory();
if (rootLoggerDirectory == null) {
return;
}
String absolutePath = new File(rootLoggerDirectory, failedMessageFile).getAbsolutePath();
try {
DailyRollingFileAppender failedLogFilesAppender = new DailyRollingFileAppender(new PatternLayout(PATTERN_SPEC_TIMESTAMP_MESSAGE_NEWLINE), absolutePath, DATE_PATTERN);
logger.addAppender(failedLogFilesAppender);
logger.setLevel(Level.ERROR);
logger.setAdditivity(false);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.log4j.DailyRollingFileAppender in project incubator-atlas by apache.
the class FailedMessagesLogger method init.
void init() {
String rootLoggerDirectory = getRootLoggerDirectory();
if (rootLoggerDirectory == null) {
return;
}
String absolutePath = new File(rootLoggerDirectory, failedMessageFile).getAbsolutePath();
try {
DailyRollingFileAppender failedLogFilesAppender = new DailyRollingFileAppender(new PatternLayout(PATTERN_SPEC_TIMESTAMP_MESSAGE_NEWLINE), absolutePath, DATE_PATTERN);
logger.addAppender(failedLogFilesAppender);
logger.setLevel(Level.ERROR);
logger.setAdditivity(false);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.log4j.DailyRollingFileAppender in project gerrit by GerritCodeReview.
the class SystemLog method createAppender.
public static Appender createAppender(Path logdir, String name, Layout layout) {
final DailyRollingFileAppender dst = new DailyRollingFileAppender();
dst.setName(name);
dst.setLayout(layout);
dst.setEncoding(UTF_8.name());
dst.setFile(resolve(logdir).resolve(name).toString());
dst.setImmediateFlush(true);
dst.setAppend(true);
dst.setErrorHandler(new DieErrorHandler());
dst.activateOptions();
dst.setErrorHandler(new OnlyOnceErrorHandler());
return dst;
}
Aggregations