当前位置: 首页>>代码示例>>Java>>正文


Java RollingFileAppender类代码示例

本文整理汇总了Java中org.apache.log4j.rolling.RollingFileAppender的典型用法代码示例。如果您正苦于以下问题:Java RollingFileAppender类的具体用法?Java RollingFileAppender怎么用?Java RollingFileAppender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RollingFileAppender类属于org.apache.log4j.rolling包,在下文中一共展示了RollingFileAppender类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupLogging

import org.apache.log4j.rolling.RollingFileAppender; //导入依赖的package包/类
public static void setupLogging(File logDir) {
    System.getProperties().setProperty("log4j.defaultInitOverride", "true");

    RollingFileAppender appender = new RollingFileAppender();
    appender.setFile(new File(logDir, "celos.log").getAbsolutePath());
    appender.setAppend(true);

    TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
    rollingPolicy.setFileNamePattern(new File(logDir, "celos-%d{yyyy-MM-dd}.log").getAbsolutePath());
    appender.setRollingPolicy(rollingPolicy);

    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setConversionPattern("[%d{YYYY-MM-dd HH:mm:ss.SSS}] %-5p: %m%n");
    appender.setLayout(patternLayout);

    appender.activateOptions();
    Logger.getRootLogger().addAppender(appender);
    Logger.getRootLogger().setLevel(Level.INFO);
}
 
开发者ID:collectivemedia,项目名称:celos,代码行数:20,代码来源:Util.java

示例2: createNewAppender

import org.apache.log4j.rolling.RollingFileAppender; //导入依赖的package包/类
public Set<? extends Appender> createNewAppender(final String appenderName,
                                                 final String logFolderFullPath,
                                                 final String shortFileName) {

  final String fullFileName = FilenameUtils.concat(logFolderFullPath, shortFileName);
  final String fileNamePattern = String.format("%s.%s", fullFileName, suffixPattern);

  final RollingFileAppender rollingFileAppender = new RollingFileAppender();
  rollingFileAppender.setName(appenderName);
  rollingFileAppender.setImmediateFlush(immediateFlush);

  Runtime.getRuntime().addShutdownHook(new Thread(LogManager::shutdown));

  rollingFileAppender.setLayout(new EnhancedPatternLayout(layout));

  final TimeBasedRollingPolicy timeBasedRollingPolicy = getTimeBasedRollingPolicy(fileNamePattern);
  rollingFileAppender.setRollingPolicy(timeBasedRollingPolicy);

  rollingFileAppender.activateOptions();

  return Collections.singleton(rollingFileAppender);
}
 
开发者ID:outbrain,项目名称:Aletheia,代码行数:23,代码来源:ExtrasRollingAppenderFactory.java

示例3: main

import org.apache.log4j.rolling.RollingFileAppender; //导入依赖的package包/类
public static void main(String[] args) throws TwitterException {
    PatternLayout layoutStandard = new PatternLayout();
    layoutStandard.setConversionPattern("[%p] %d %c %M - %m%n");

    PatternLayout layoutSimple = new PatternLayout();
    layoutSimple.setConversionPattern("%m%n");

    // Filter for the statuses: we only want INFO messages
    LevelRangeFilter filter = new LevelRangeFilter();
    filter.setLevelMax(Level.INFO);
    filter.setLevelMin(Level.INFO);
    filter.setAcceptOnMatch(true);
    filter.activateOptions();

    TimeBasedRollingPolicy statusesRollingPolicy = new TimeBasedRollingPolicy();
    statusesRollingPolicy.setFileNamePattern("statuses.log" + HOUR_ROLL);
    statusesRollingPolicy.activateOptions();

    RollingFileAppender statusesAppender = new RollingFileAppender();
    statusesAppender.setRollingPolicy(statusesRollingPolicy);
    statusesAppender.addFilter(filter);
    statusesAppender.setLayout(layoutSimple);
    statusesAppender.activateOptions();

    TimeBasedRollingPolicy warningsRollingPolicy = new TimeBasedRollingPolicy();
    warningsRollingPolicy.setFileNamePattern("warnings.log" + HOUR_ROLL);
    warningsRollingPolicy.activateOptions();

    RollingFileAppender warningsAppender = new RollingFileAppender();
    warningsAppender.setRollingPolicy(statusesRollingPolicy);
    warningsAppender.setThreshold(Level.WARN);
    warningsAppender.setLayout(layoutStandard);
    warningsAppender.activateOptions();

    ConsoleAppender consoleAppender = new ConsoleAppender();
    consoleAppender.setThreshold(Level.WARN);
    consoleAppender.setLayout(layoutStandard);
    consoleAppender.activateOptions();

    // configures the root logger
    Logger rootLogger = Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    rootLogger.removeAllAppenders();
    rootLogger.addAppender(consoleAppender);
    rootLogger.addAppender(statusesAppender);
    rootLogger.addAppender(warningsAppender);

    // creates a custom logger and log messages
    final Logger logger = Logger.getLogger(SimpleStreamCollector.class);

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    RawStreamListener rawListener = new RawStreamListener() {

        @Override
        public void onMessage(String rawString) {
            cnt++;
            logger.info(rawString);
            if (cnt % 1000 == 0) {
                System.out.println(cnt + " messages received.");
            }
        }

        @Override
        public void onException(Exception ex) {
            logger.warn(ex);
        }

    };

    twitterStream.addListener(rawListener);
    twitterStream.sample();
}
 
开发者ID:Remper,项目名称:sociallink,代码行数:73,代码来源:SimpleStreamCollector.java


注:本文中的org.apache.log4j.rolling.RollingFileAppender类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。