org.apache.log4j.DailyRollingFileAppender Java Examples

The following examples show how to use org.apache.log4j.DailyRollingFileAppender. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FailedMessagesLogger.java    From atlas with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #2
Source File: FailedMessagesLogger.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #3
Source File: FairSchedulerEventLog.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #4
Source File: FairSchedulerEventLog.java    From big-c with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: DynamicLog4jLogger.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
private Appender buildAppender(String name, String fileName, String pattern) {
    DailyRollingFileAppender appender = new DailyRollingFileAppender();
    appender.setName(name);
    appender.setAppend(true);
    appender.setEncoding(getEncoding());
    appender.setLayout(new PatternLayout(pattern));
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());
    appender.activateOptions();// 很重要,否则原有日志内容会被清空
    return appender;
}
 
Example #6
Source File: DynamicLog4jLogger.java    From tddl with Apache License 2.0 5 votes vote down vote up
private Appender buildAppender(String name, String fileName, String pattern) {
    DailyRollingFileAppender appender = new DailyRollingFileAppender();
    appender.setName(name);
    appender.setAppend(true);
    appender.setEncoding(getEncoding());
    appender.setLayout(new PatternLayout(pattern));
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());
    appender.activateOptions();// 很重要,否则原有日志内容会被清空
    return appender;
}