java类org.apache.log4j.DailyRollingFileAppender的实例源码

Log.java 文件源码 项目:traccar-service 阅读 29 收藏 0 点赞 0 评论 0
public static void setupLogger(Config config) throws IOException {

        Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");

        Appender appender = new DailyRollingFileAppender(
                layout, config.getString("logger.file"), "'.'yyyyMMdd");

        LogManager.resetConfiguration();
        LogManager.getRootLogger().addAppender(new NullAppender());

        logger = Logger.getLogger(LOGGER_NAME);
        logger.addAppender(appender);
        logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));

        // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
        InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
            @Override
            public InternalLogger newInstance(String string) {
                return new NettyInternalLogger();
            }
        });

        Log.logSystemInfo();
        Log.info("Version: " + getAppVersion());
    }
LogUtils.java 文件源码 项目:Jerkoff 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 
 * @param prop
 * @param clazz
 * @return
 */
public static Logger getLogger(Properties prop, Class<?> clazz) {
    Logger LOG = Logger.getLogger(clazz);
    String appName = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.APP_NAME);
    String fileDir = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_DIR);
    String patternLayout = PropertiesUtils.getRequiredProperty(prop,
            PropertiesUtils.LOG_PATTERN);
    String level = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_LEVEL);
    LOG.setLevel(Level.toLevel(level, Level.INFO));
    DailyRollingFileAppender rollingAppender = new DailyRollingFileAppender();
    rollingAppender.setFile(fileDir + "/" + appName + ".log");
    rollingAppender.setLayout(new PatternLayout(patternLayout));
    rollingAppender.setDatePattern("'.'yyyy-MM-dd");
    rollingAppender.activateOptions();
    LOG.addAppender(rollingAppender);
    LOG.setAdditivity(false);
    return LOG;
}
Log4jComponent.java 文件源码 项目:jlogstash 阅读 14 收藏 0 点赞 0 评论 0
public void setLevel(DailyRollingFileAppender fa){
    if (CmdLineParams.hasOptionTrace()) {
        fa.setThreshold(Level.TRACE);
        Logger.getRootLogger().setLevel(Level.TRACE);
    } else if (CmdLineParams.hasOptionDebug()) {
        fa.setThreshold(Level.DEBUG);
    } else if (CmdLineParams.hasOptionInfo()) {
        fa.setThreshold(Level.INFO);
    } else if(CmdLineParams.hasOptionWarn()){
        fa.setThreshold(Level.WARN);
    }else if(CmdLineParams.hasOptionError()){
        fa.setThreshold(Level.ERROR);
    }else {
        fa.setThreshold(Level.WARN);
    }
}
SeedboxSync.java 文件源码 项目:SeedboxSync 阅读 15 收藏 0 点赞 0 评论 0
/**
 * Configures the logger.
 */
private static void configureLogging() {
    PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd' 'HH:mm:ss.SSS} [%-5p] [%c] - %m%n");

    ConsoleAppender console = new ConsoleAppender();
    console.setLayout(layout);
    console.setThreshold(Level.INFO);
    console.activateOptions();

    DailyRollingFileAppender file = new DailyRollingFileAppender();
    file.setFile("log/app.log");
    file.setDatePattern("'.'yyyy-MM-dd");
    file.setLayout(layout);
    file.activateOptions();

    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
    logger.addAppender(console);
    logger.addAppender(file);
}
FairSchedulerEventLog.java 文件源码 项目:hadoop-plus 阅读 28 收藏 0 点赞 0 评论 0
boolean init(FairSchedulerConfiguration conf) {
  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;
  }
  return !(logDisabled);
}
FailedMessagesLogger.java 文件源码 项目:incubator-atlas 阅读 20 收藏 0 点赞 0 评论 0
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();
    }
}
LoggerUtils.java 文件源码 项目:resource_access_tools 阅读 25 收藏 0 点赞 0 评论 0
/**
 * This create log4j logger for resource access tool using root logger.
 * It adds file appender with specified filename to the logger which creates separate
 * log file for each resource access tool.
 *
 * @param clazz   Class object for Resource Access Tool
 * @param logFile String containing name of log file.
 * @return log4j Logger object
 */
@SuppressWarnings("unchecked")
public static Logger createRATSpecificLogger(Class clazz, String logFile) {
    Enumeration<Appender> appenders = Logger.getRootLogger()
            .getAllAppenders();
    // Add all appenders of root logger
    while (appenders.hasMoreElements()) {
        Appender appender = appenders.nextElement();

        //  For file appender create new appender with different log file
        if (appender instanceof DailyRollingFileAppender) {
            try {
                // Creates new file appender
                ((DailyRollingFileAppender) appender).setFile(FileParameters.obrLogFolder() + logFile);
                ((DailyRollingFileAppender) appender).activateOptions();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return Logger.getLogger(clazz);
}
LoggerUtils.java 文件源码 项目:resource_access_tools 阅读 22 收藏 0 点赞 0 评论 0
/**
 * This create log4j logger for OBS work flow using root logger.
 * It adds file appender with specified filename to the logger which creates separate
 * log file for each resource access tool.
 *
 * @param clazz
 * @param logFile String containing name of log file.
 * @return log4j Logger object
 */
@SuppressWarnings("unchecked")
public static Logger createOBSLogger(Class clazz) {

    Enumeration<Appender> appenders = Logger.getRootLogger()
            .getAllAppenders();
    // Add all appenders of root logger
    while (appenders.hasMoreElements()) {
        Appender appender = appenders.nextElement();

        //  For file appender create new appender with different log file
        if (appender instanceof DailyRollingFileAppender) {
            try {
                // Creates new file appender
                ((DailyRollingFileAppender) appender).setFile(FileParameters.obsLogFolder() + OBS_LOG_FILE);
                ((DailyRollingFileAppender) appender).activateOptions();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return Logger.getLogger(clazz);
}
Log.java 文件源码 项目:traccar-mongodb 阅读 32 收藏 0 点赞 0 评论 0
public static void setupLogger(Properties properties) throws IOException {

        Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %5p: %m%n");

        Appender appender = new DailyRollingFileAppender(
                layout, properties.getProperty("logger.file"), "'.'yyyyMMdd");

        LogManager.resetConfiguration();
        logger = Logger.getLogger(LOGGER_NAME);
        logger.addAppender(appender);
        logger.setLevel(Level.ALL);

        // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
        InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
            @Override
            public InternalLogger newInstance(String string) {
                return new NettyInternalLogger();
            }
        });
    }
FairSchedulerEventLog.java 文件源码 项目:hadoop-TCP 阅读 21 收藏 0 点赞 0 评论 0
boolean init(FairSchedulerConfiguration conf) {
  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;
  }
  return !(logDisabled);
}
FairSchedulerEventLog.java 文件源码 项目:hardfs 阅读 25 收藏 0 点赞 0 评论 0
boolean init(FairSchedulerConfiguration conf) {
  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;
  }
  return !(logDisabled);
}
LoggingSystem.java 文件源码 项目:FallenGalaxy 阅读 25 收藏 0 点赞 0 评论 0
public static Logger getServerLogger() {
    if (serverLogger == null) {
        // Initialise le gestionnaire de logs
        try {
            DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
                    new PatternLayout("%-5p %d{HH:mm:ss} %m%n"),
                    Config.getServerLogFile(), "'.'yyyy-MM-dd");

            serverLogger = Logger.getLogger("server");
            serverLogger.addAppender(fileAppender);
            serverLogger.setLevel(Level.toLevel(Config.getServerLogLevel()));

            if (Config.isDebug()) {
                ConsoleAppender consoleAppender = new ConsoleAppender(
                        new PatternLayout("%-5p %d{HH:mm:ss} %m [%C#%M, line %L]%n"));
                serverLogger.addAppender(consoleAppender);
            }
        } catch (IOException e) {
            System.err.println("Could not initialize server logging!");
            e.printStackTrace();
        }

        serverLogger.info("Server logging initialized.");
    }
    return serverLogger;
}
LoggingSystem.java 文件源码 项目:FallenGalaxy 阅读 16 收藏 0 点赞 0 评论 0
public static Logger getPremiumLogger() {
    if (premiumLogger == null) {
        // Initialise le gestionnaire de logs
        try {
            DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
                    new PatternLayout("%-5p %d{HH:mm:ss} %m%n"),
                    Config.getPremiumLogFile(), "'.'yyyy-MM-dd");

            premiumLogger = Logger.getLogger("premium");
            premiumLogger.addAppender(fileAppender);
            premiumLogger.setLevel(Level.DEBUG);

            if (Config.isDebug()) {
                ConsoleAppender consoleAppender = new ConsoleAppender(
                        new PatternLayout("%-5p %d{HH:mm:ss} %m [%C#%M, line %L]%n"));
                premiumLogger.addAppender(consoleAppender);
            }
        } catch (IOException e) {
            System.err.println("Could not initialize premium transactions logging!");
            e.printStackTrace();
        }

        premiumLogger.info("Premium transactions logging initialized.");
    }
    return premiumLogger;
}
LoggingSystem.java 文件源码 项目:FallenGalaxy 阅读 27 收藏 0 点赞 0 评论 0
public static Logger getChatLogger() {
        if (chatLogger == null) {
            try {
                DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
                        new PatternLayout("%d{HH:mm:ss} %m%n"),
                        Config.getChatLogFile(), "'.'yyyy-MM-dd");

                chatLogger = Logger.getLogger("chat");
                chatLogger.addAppender(fileAppender);
                chatLogger.setLevel(Level.DEBUG);

//              if (Config.isDebug()) {
//                  ConsoleAppender consoleAppender = new ConsoleAppender(
//                          new PatternLayout("%d{HH:mm:ss} %m%n"));
//                  chatLogger.addAppender(consoleAppender);
//              }
            } catch (IOException e) {
                System.err.println("Could not initialize chat logging!");
                e.printStackTrace();
            }
        }

        return chatLogger;
    }
LoggingSystem.java 文件源码 项目:FallenGalaxy 阅读 17 收藏 0 点赞 0 评论 0
public static Logger getActionLogger() {
        if (actionLogger == null) {
            try {
                DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
                        new PatternLayout("%d{HH:mm:ss} %m%n"),
                        Config.getActionLogFile(), "'.'yyyy-MM-dd");

                actionLogger = Logger.getLogger("action");
                actionLogger.addAppender(fileAppender);
                actionLogger.setLevel(Level.DEBUG);

//              if (Config.isDebug()) {
//                  ConsoleAppender consoleAppender = new ConsoleAppender(
//                          new PatternLayout("%d{HH:mm:ss} %m%n"));
//                  actionLogger.addAppender(consoleAppender);
//              }
            } catch (IOException e) {
                System.err.println("Could not initialize action logging!");
                e.printStackTrace();
            }
        }

        return actionLogger;
    }
SecureLog.java 文件源码 项目:build-management 阅读 15 收藏 0 点赞 0 评论 0
/**
 * Constructs a log which writes log entries to the given log file.
 *
 * @param title     Identifies the log entries
 * @param logfile   Location of the log file
 */
public SecureLog(String title, String logfile) throws IOException {
    defaultLog = new FileOutputStream(logfile);
    logAppender = new DailyRollingFileAppender(defaultLayout, logfile, rotationInterval);
    logAppender.setName(defaultLogName);

    // Configure the logging options
    //logRoot = new SecureCategory(title);
    logRoot = (SecureCategory)SecureCategory.getLogger(title);

    logRoot.addAppender(logAppender);
    setLogLevel(DEBUG);
    logEntry(this, DEBUG, 
        "Constructing " + title + " log.  Initial log level is DEBUG.  " +
        "Output will be sent to: " + logfile);
}
FairSchedulerEventLog.java 文件源码 项目:hadoop 阅读 21 收藏 0 点赞 0 评论 0
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);
}
FairSchedulerEventLog.java 文件源码 项目:aliyun-oss-hadoop-fs 阅读 27 收藏 0 点赞 0 评论 0
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);
}
Log4jComponent.java 文件源码 项目:jlogstash 阅读 16 收藏 0 点赞 0 评论 0
@Override
public void setupLogger() {
    String file =checkFile();
    DailyRollingFileAppender fa = new DailyRollingFileAppender();
    fa.setName("FileLogger");
    fa.setFile(file);
    fa.setLayout(new PatternLayout(pattern));
    setLevel(fa);
    fa.setAppend(true);
    fa.activateOptions();
    Logger.getRootLogger().addAppender(fa);
}
DailyAutoRollingFileAppender.java 文件源码 项目:leopard 阅读 18 收藏 0 点赞 0 评论 0
protected void initFields() throws Exception {
    nextCheckField = DailyRollingFileAppender.class.getDeclaredField("nextCheck");
    nowField = DailyRollingFileAppender.class.getDeclaredField("now");
    rcField = DailyRollingFileAppender.class.getDeclaredField("rc");
    scheduledFilenameField = DailyRollingFileAppender.class.getDeclaredField("scheduledFilename");

    nextCheckField.setAccessible(true);
    nowField.setAccessible(true);
    rcField.setAccessible(true);
    scheduledFilenameField.setAccessible(true);
}
FairSchedulerEventLog.java 文件源码 项目:big-c 阅读 25 收藏 0 点赞 0 评论 0
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);
}
Main.java 文件源码 项目:searsiaserver 阅读 16 收藏 0 点赞 0 评论 0
/**
    * Attaches a rolling file logger for search queries
    *
    * @param path
    * @param filename
    * @throws IOException
    */
private static void setupLogger(String path, String filename, Level level) throws IOException {
       Path logDir = Paths.get(path, filename + "_log");
    if (!Files.exists(logDir)) {
        Files.createDirectories(logDir);
    }
    Appender appender = new DailyRollingFileAppender(
            new PatternLayout("%p %d{ISO8601} %m%n"),
            logDir.resolve("searsia.log").toString(),
            "'.'yyyy-MM-dd");
    LOGGER.addAppender(appender);
    LOGGER.setLevel(level);
    LOGGER.warn("Searsia restart");
}
FairSchedulerEventLog.java 文件源码 项目:hadoop-2.6.0-cdh5.4.3 阅读 20 收藏 0 点赞 0 评论 0
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);
}
FairSchedulerEventLog.java 文件源码 项目:hadoop-2.6.0-cdh5.4.3 阅读 20 收藏 0 点赞 0 评论 0
boolean init(Configuration conf, String jobtrackerHostname) {
  try {
    logDir = conf.get("mapred.fairscheduler.eventlog.location",
        new File(System.getProperty("hadoop.log.dir")).getAbsolutePath()
        + File.separator + "fairscheduler");
    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-%s.log",
        logDir, File.separator, username, jobtrackerHostname);
    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;
  }
  return !(logDisabled);
}
LoggingInitializer.java 文件源码 项目:Heap 阅读 21 收藏 0 点赞 0 评论 0
private Appender getFileAppender(Level level, String pattern, String file) {
    DailyRollingFileAppender appender = new DailyRollingFileAppender();
    appender.setFile(file);
    appender.setLayout(new PatternLayout(pattern));
    appender.setThreshold(level);
    appender.setAppend(true);
    appender.activateOptions();
    return appender;
}
DynamicLog4jLogger.java 文件源码 项目:tddl5 阅读 18 收藏 0 点赞 0 评论 0
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;
}
DynamicLog4jLogger.java 文件源码 项目:TDDL 阅读 14 收藏 0 点赞 0 评论 0
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;
}
LoggerUtils.java 文件源码 项目:resource_access_tools 阅读 22 收藏 0 点赞 0 评论 0
/**
 * This create log4j logger for OBS work flow using root logger.
 * It adds file appender with specified filename to the logger which creates separate
 * log file for each resource access tool.
 *
 * @param clazz
 * @param logFile String containing name of log file.
 * @return log4j Logger object
 */
@SuppressWarnings("unchecked")
public static Logger createOBRLogger(Class clazz) {

    Logger logger = Logger.getLogger(clazz);

    Enumeration<Appender> appenders = Logger.getRootLogger()
            .getAllAppenders();
    // Add all appenders of root logger
    while (appenders.hasMoreElements()) {
        Appender appender = appenders.nextElement();

        //  For file appender create new appender with different log file
        if (appender instanceof DailyRollingFileAppender) {
            try {
                // Creates new file appender
                DailyRollingFileAppender newFileAppender = new DailyRollingFileAppender(
                        appender.getLayout(), FileParameters.obrLogFolder() + OBR_LOG_FILE,
                        ((DailyRollingFileAppender) appender)
                                .getDatePattern());
                newFileAppender.activateOptions();

                logger.addAppender(newFileAppender);

            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            logger.addAppender(appender);
        }
    }

    logger.setAdditivity(false);

    return logger;

}
SystemLog.java 文件源码 项目:gerrit 阅读 17 收藏 0 点赞 0 评论 0
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;
}
FairSchedulerEventLog.java 文件源码 项目:hops 阅读 21 收藏 0 点赞 0 评论 0
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);
}


问题


面经


文章

微信
公众号

扫码关注公众号