本文整理汇总了Java中org.apache.log4j.rolling.RollingFileAppender.activateOptions方法的典型用法代码示例。如果您正苦于以下问题:Java RollingFileAppender.activateOptions方法的具体用法?Java RollingFileAppender.activateOptions怎么用?Java RollingFileAppender.activateOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.rolling.RollingFileAppender
的用法示例。
在下文中一共展示了RollingFileAppender.activateOptions方法的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);
}
示例2: 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();
}
示例3: 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);
}