Search in sources :

Example 1 with DailyRollingFileAppender

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);
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) File(java.io.File) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender)

Example 2 with DailyRollingFileAppender

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());
        }
    }
}
Also used : DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) Field(java.lang.reflect.Field) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException)

Example 3 with DailyRollingFileAppender

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();
    }
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) File(java.io.File) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender)

Example 4 with DailyRollingFileAppender

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();
    }
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) File(java.io.File) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender)

Example 5 with DailyRollingFileAppender

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;
}
Also used : DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) OnlyOnceErrorHandler(org.apache.log4j.helpers.OnlyOnceErrorHandler)

Aggregations

DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)11 PatternLayout (org.apache.log4j.PatternLayout)6 IOException (java.io.IOException)5 File (java.io.File)4 Appender (org.apache.log4j.Appender)4 FileAppender (org.apache.log4j.FileAppender)3 Logger (org.apache.log4j.Logger)3 Layout (org.apache.log4j.Layout)2 OnlyOnceErrorHandler (org.apache.log4j.helpers.OnlyOnceErrorHandler)2 NullAppender (org.apache.log4j.varia.NullAppender)2 AbstractInternalLogger (org.jboss.netty.logging.AbstractInternalLogger)2 InternalLogger (org.jboss.netty.logging.InternalLogger)2 InternalLoggerFactory (org.jboss.netty.logging.InternalLoggerFactory)2 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Field (java.lang.reflect.Field)1 SocketException (java.net.SocketException)1 Path (java.nio.file.Path)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConsoleAppender (org.apache.log4j.ConsoleAppender)1