• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SizeAndTimeBasedFNATP类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createDailyLogAppender

import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP; //导入依赖的package包/类
/**
 * Create an appender that will create a new log each day
 * 
 * @param context
 * @param encoder
 * @return An appender that matches the set up of the logger builder
 */
private RollingFileAppender<ILoggingEvent> createDailyLogAppender(LoggerContext context, Encoder<ILoggingEvent> encoder){
	RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
	appender.setEncoder(encoder);
	appender.setFile(file);
	
	TimeBasedRollingPolicy<ILoggingEvent> rolling = new TimeBasedRollingPolicy<>();
	rolling.setContext(context);
	rolling.setParent(appender);
	
	rolling.setFileNamePattern(getFileWithPattern("%d"));
	
	//Set the maximum number of logs, either to the user specified setting or default to 1
	if (maxNumberLogs.isPresent() && maxNumberLogs.get() >= 0) {
		rolling.setMaxHistory(maxNumberLogs.get());
	} else {
		rolling.setMaxHistory(1);
	}

	//Do we need to also split files by size? 
	if (divideBasedOnSize()) {
		SizeAndTimeBasedFNATP<ILoggingEvent> sizeBased = new SizeAndTimeBasedFNATP<>();
		sizeBased.setContext(context);
		sizeBased.setMaxFileSize(getMaxFileSize());
		sizeBased.setTimeBasedRollingPolicy(rolling);

		rolling.setTimeBasedFileNamingAndTriggeringPolicy(sizeBased);
	}

	rolling.start();
	if(rolling.getTimeBasedFileNamingAndTriggeringPolicy() != null){
		rolling.getTimeBasedFileNamingAndTriggeringPolicy().start();
	}
	appender.setRollingPolicy(rolling);
	
	return appender;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:44,代码来源:BaleenFileLoggerBuilder.java


示例2: PhialLogger

import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP; //导入依赖的package包/类
/**
 * Creates Logger that will write logs in html file using slf4j and logback.
 * The logs will be included in Phial Attachment
 *
 * @param context application context
 */
public PhialLogger(Context context) {
    logDir = createLogDir(context);
    clearOldLogs(logDir);

    final String logDirectory = logDir.getAbsolutePath();
    // reset the default context (which may already have been initialized)
    // since we want to reconfigure it
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    loggerContext.reset();

    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
    rollingFileAppender.setContext(loggerContext);
    rollingFileAppender.setAppend(true);
    rollingFileAppender.setFile(logDirectory + "/" + LOG_PREFIX + "-latest.html");

    SizeAndTimeBasedFNATP<ILoggingEvent> fileNamingPolicy = new SizeAndTimeBasedFNATP<>();
    fileNamingPolicy.setContext(loggerContext);
    fileNamingPolicy.setMaxFileSize(MAX_FILE_SIZE);

    TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>();
    rollingPolicy.setContext(loggerContext);
    rollingPolicy.setFileNamePattern(logDirectory + "/" + LOG_PREFIX + HISTORY_FILE_NAME_PATTERN);
    rollingPolicy.setMaxHistory(5);
    rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(fileNamingPolicy);
    rollingPolicy.setParent(rollingFileAppender);  // parent and context required!
    rollingPolicy.start();

    HTMLLayout htmlLayout = new HTMLLayout();
    htmlLayout.setContext(loggerContext);
    htmlLayout.setPattern(PATTERN);
    htmlLayout.start();

    LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
    encoder.setContext(loggerContext);
    encoder.setLayout(htmlLayout);
    encoder.start();

    rollingFileAppender.setRollingPolicy(rollingPolicy);
    rollingFileAppender.setEncoder(encoder);
    rollingFileAppender.start();

    // add the newly created appenders to the root logger;
    // qualify Logger to disambiguate from org.slf4j.Logger
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.DEBUG);
    root.addAppender(rollingFileAppender);
    // print any status messages (warnings, etc) encountered in logback config
    StatusPrinter.print(loggerContext);
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:56,代码来源:PhialLogger.java


示例3: testConfigureRollingFileAppender

import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP; //导入依赖的package包/类
@Test
public void testConfigureRollingFileAppender() {
	System.setProperty("config.file", "src/test/resources/rollingFileAppender.conf");
	ConfigFactory.invalidateCaches();

	LoggerContext context = new LoggerContext();
	ConfigConfigurator configurator = new ConfigConfigurator();
	configurator.configure(context);

	int errorCount = 0;
	int warningCount = 0;
	for (Status status : context.getStatusManager().getCopyOfStatusList()) {
		if (status.getLevel() == Status.ERROR) {
			System.out.println(String.format("ERROR : %s", status.getMessage()));
			errorCount++;
		} else if (status.getLevel() == Status.WARN) {
			System.out.println(String.format("WARN : %s", status.getMessage()));
			warningCount++;
		} else if (status.getLevel() == Status.INFO) {
			System.out.println(String.format("INFO : %s", status.getMessage()));
		}

	}
	assertEquals(0, errorCount);
	assertEquals(0, warningCount);

	Logger rootLogger = context.getLoggerList().get(0);
	Appender<?> appender = rootLogger.getAppender("rolling");
	assertTrue(appender.isStarted());

	assertTrue(appender instanceof RollingFileAppender);

	RollingFileAppender<?> rolling = (RollingFileAppender<?>) appender;
	assertTrue(rolling.getEncoder() instanceof PatternLayoutEncoder);
	assertTrue(rolling.isStarted());

	PatternLayoutEncoder encoder = (PatternLayoutEncoder) rolling.getEncoder();
	assertEquals(Charset.forName("UTF-8"), encoder.getCharset());
	assertEquals("%date %level %logger %thread %msg%n", encoder.getPattern());

	assertEquals("logs/test.log", rolling.getFile());

	assertTrue(rolling.getRollingPolicy() instanceof TimeBasedRollingPolicy);
	TimeBasedRollingPolicy<?> rollingPolicy = (TimeBasedRollingPolicy<?>) rolling.getRollingPolicy();

	assertEquals("logs/test%d{yyyy-MM-dd}.%i.log", rollingPolicy.getFileNamePattern());
	assertEquals(30, rollingPolicy.getMaxHistory());
	assertTrue(rollingPolicy.isStarted());

	assertTrue(rollingPolicy.getTimeBasedFileNamingAndTriggeringPolicy() instanceof SizeAndTimeBasedFNATP);

	SizeAndTimeBasedFNATP<?> triggeringPolicy = (SizeAndTimeBasedFNATP<?>) rollingPolicy.getTimeBasedFileNamingAndTriggeringPolicy();
	assertEquals("5MB", triggeringPolicy.getMaxFileSize());
	assertTrue(triggeringPolicy.isStarted());
}
 
开发者ID:gnieh,项目名称:logback-config,代码行数:56,代码来源:ConfigConfiguratorTest.java


示例4: initLogs

import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP; //导入依赖的package包/类
private static void initLogs() {
    Logger logbackLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    LoggerContext lc = logbackLogger.getLoggerContext();

    Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.detachAndStopAllAppenders();

    TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
    rollingPolicy.setMaxHistory(3);
    SizeAndTimeBasedFNATP<ILoggingEvent> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<ILoggingEvent>();
    sizeAndTimeBasedFNATP.setMaxFileSize("2MB");
    rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(sizeAndTimeBasedFNATP);
    rollingPolicy.setFileNamePattern(context.getFilesDir().getPath() + "/logs/old/flickruploader.%d{yyyy-MM-dd}.%i.log");
    rollingPolicy.setContext(lc);

    RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(lc);
    fileAppender.setFile(getLogFilePath());
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.setTriggeringPolicy(rollingPolicy);
    rollingPolicy.setParent(fileAppender);

    PatternLayoutEncoder pl = new PatternLayoutEncoder();
    pl.setContext(lc);
    pl.setCharset(Charset.defaultCharset());
    pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %class{0}.%method:%L > %msg%n");
    pl.setImmediateFlush(false);
    pl.start();

    fileAppender.setEncoder(pl);
    fileAppender.setName("file");

    rollingPolicy.start();
    fileAppender.start();

    if (Config.isDebug()) {
        final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
        logcatTagPattern.setContext(lc);
        logcatTagPattern.setPattern("%class{0}");
        logcatTagPattern.start();

        final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder();
        logcatPattern.setContext(lc);
        logcatPattern.setPattern("[%thread] %method:%L > %msg%n");
        logcatPattern.start();

        final LogcatAppender logcatAppender = new LogcatAppender();
        logcatAppender.setContext(lc);
        logcatAppender.setTagEncoder(logcatTagPattern);
        logcatAppender.setEncoder(logcatPattern);
        logcatAppender.start();

        rootLogger.addAppender(logcatAppender);
    }

    rootLogger.addAppender(fileAppender);

}
 
开发者ID:rafali,项目名称:flickr-uploader,代码行数:59,代码来源:FlickrUploader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java S3VersionSummary类代码示例发布时间:2022-05-23
下一篇:
Java PersistentIdGenerator类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap