當前位置: 首頁>>代碼示例>>Java>>正文


Java TimeBasedRollingPolicy.setMaxHistory方法代碼示例

本文整理匯總了Java中ch.qos.logback.core.rolling.TimeBasedRollingPolicy.setMaxHistory方法的典型用法代碼示例。如果您正苦於以下問題:Java TimeBasedRollingPolicy.setMaxHistory方法的具體用法?Java TimeBasedRollingPolicy.setMaxHistory怎麽用?Java TimeBasedRollingPolicy.setMaxHistory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ch.qos.logback.core.rolling.TimeBasedRollingPolicy的用法示例。


在下文中一共展示了TimeBasedRollingPolicy.setMaxHistory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildDailyMaxRollingAppender

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
protected Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    layout.start();
    appender.setEncoder(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:26,代碼來源:DynamicLogbackLogger.java

示例2: buildDailyMaxRollingAppender

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
protected Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayout layout = new PatternLayout();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.start();
    appender.setLayout(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:25,代碼來源:DynamicLogback918Logger.java

示例3: buildDailyMaxRollingAppender

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
private Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    appender.setEncoder(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:21,代碼來源:DynamicLogbackLogger.java

示例4: addFileAppender

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
public static void addFileAppender(String name, String logPattern, String filePath, int maxHistory) {
	RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
       fileAppender.setFile(filePath);
       fileAppender.setEncoder(getPatternLayoutEncoder(logPattern));
       fileAppender.setContext(loggerContext);
       fileAppender.setName(name);
       fileAppender.setAppend(true);
       
       // time based rolling policy
       TimeBasedRollingPolicy<ILoggingEvent> logFilePolicy = new TimeBasedRollingPolicy<>();
    logFilePolicy.setContext(loggerContext);
    logFilePolicy.setParent(fileAppender);
    logFilePolicy.setFileNamePattern(getDateBasedFileName(filePath));
    logFilePolicy.setMaxHistory(50);
    logFilePolicy.start();
    
    fileAppender.setRollingPolicy(logFilePolicy);
       fileAppender.start();

       registeredAppenders.put(name, fileAppender);
}
 
開發者ID:sangupta,項目名稱:jerry-core,代碼行數:22,代碼來源:ApplicationLogger.java

示例5: doInitializer

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
/**
 * Initializer logback
 * 
 * @param file
 * @param level
 * @param maxHistory
 */
private void doInitializer(String file, String level, int maxHistory) {
	LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
	rootLogger.detachAndStopAllAppenders();

	// appender
	RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
	fileAppender.setContext(loggerContext);
	fileAppender.setName("application");
	fileAppender.setFile(file);
	fileAppender.setAppend(true);

	// policy
	TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
	policy.setContext(loggerContext);
	policy.setMaxHistory(maxHistory);
	policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
	policy.setParent(fileAppender);
	policy.start();
	fileAppender.setRollingPolicy(policy);

	// encoder
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	encoder.setContext(loggerContext);
	encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
	encoder.start();
	fileAppender.setEncoder(encoder);
	
	fileAppender.start();

	rootLogger.addAppender(fileAppender);
	rootLogger.setLevel(Level.toLevel(level));
	rootLogger.setAdditive(false);
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:42,代碼來源:LogbackContainer.java

示例6: setupLogger

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
@Override
public void setupLogger() {
    String file = checkFile();
       LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
       Logger newLogger =loggerContext.getLogger("ROOT");
       //Remove all previously added appenders from this logger instance.
       newLogger.detachAndStopAllAppenders();
       //define appender
       RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
       //policy
       TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
       policy.setContext(loggerContext);
       policy.setMaxHistory(day);
       policy.setFileNamePattern(formateLogFile(file));
       policy.setParent(appender);
       policy.start();
       //encoder
       PatternLayoutEncoder encoder = new PatternLayoutEncoder();
       encoder.setContext(loggerContext);
       encoder.setPattern(formatePattern);
       encoder.start();
       //start appender
       appender.setRollingPolicy(policy);
       appender.setContext(loggerContext);
       appender.setEncoder(encoder);
       appender.setPrudent(true); //support that multiple JVMs can safely write to the same file.
       appender.start();
       newLogger.addAppender(appender);
       //setup level
       setLevel(newLogger);
       //remove the appenders that inherited 'ROOT'.
       newLogger.setAdditive(false);
}
 
開發者ID:DTStack,項目名稱:jlogstash,代碼行數:34,代碼來源:LogbackComponent.java

示例7: doInitializer

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
/**
 * Initializer logback
 *
 * @param file       log file
 * @param level      log level
 * @param maxHistory max history
 */
private void doInitializer(String file, String level, int maxHistory) {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.detachAndStopAllAppenders();

    // appender
    RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<>();
    fileAppender.setContext(loggerContext);
    fileAppender.setName("application");
    fileAppender.setFile(file);
    fileAppender.setAppend(true);

    // policy
    TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<>();
    policy.setContext(loggerContext);
    policy.setMaxHistory(maxHistory);
    policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
    policy.setParent(fileAppender);
    policy.start();
    fileAppender.setRollingPolicy(policy);

    // encoder
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
    encoder.start();
    fileAppender.setEncoder(encoder);

    fileAppender.start();

    rootLogger.addAppender(fileAppender);
    rootLogger.setLevel(Level.toLevel(level));
    rootLogger.setAdditive(false);
}
 
開發者ID:linux-china,項目名稱:dubbo3,代碼行數:42,代碼來源:LogbackContainer.java

示例8: createDailyLogAppender

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的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

示例9: setupBasePolicySettings

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
protected void setupBasePolicySettings(TimeBasedRollingPolicy<ILoggingEvent> policy) {
    policy.setFileNamePattern(getFileNamePattern());
    if (getHistorySize() > 0) {
        policy.setMaxHistory(getHistorySize());
        policy.setCleanHistoryOnStart(true);
    }
    if (totalSize != null && totalSize.length() > 0) {
        policy.setTotalSizeCap(FileSize.valueOf(totalSize));
    }
}
 
開發者ID:bootique,項目名稱:bootique-logback,代碼行數:11,代碼來源:TimeBasedPolicyFactory.java

示例10: doInitializer

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
/**
 * Initializer logback
 *
 * @param file
 * @param level
 * @param maxHistory
 */
private void doInitializer(String file, String level, int maxHistory) {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.detachAndStopAllAppenders();

    // appender
    RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(loggerContext);
    fileAppender.setName("application");
    fileAppender.setFile(file);
    fileAppender.setAppend(true);

    // policy
    TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
    policy.setContext(loggerContext);
    policy.setMaxHistory(maxHistory);
    policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
    policy.setParent(fileAppender);
    policy.start();
    fileAppender.setRollingPolicy(policy);

    // encoder
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
    encoder.start();
    fileAppender.setEncoder(encoder);

    fileAppender.start();

    rootLogger.addAppender(fileAppender);
    rootLogger.setLevel(Level.toLevel(level));
    rootLogger.setAdditive(false);
}
 
開發者ID:hufeng,項目名稱:dubbo2.js,代碼行數:42,代碼來源:LogbackContainer.java

示例11: DefaultTransactionLogHandler

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
public DefaultTransactionLogHandler(final DefaultTransactionLogHandlerConfig logConfig,
		final ObjectMapper mapper) {
	final LoggerContext loggerContext = (LoggerContext) LoggerFactory
			.getILoggerFactory();
	final PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
	patternLayoutEncoder
			.setPattern("%date{\"yyyy-MM-dd HH:mm:ss.SSS z\",UTC} %msg%n");
	patternLayoutEncoder.setContext(loggerContext);
	patternLayoutEncoder.start();

	final RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
	fileAppender.setContext(loggerContext);
	fileAppender.setAppend(true);
	fileAppender.setEncoder(patternLayoutEncoder);
	fileAppender.setPrudent(false);
	fileAppender.setFile(logConfig.getTransactionLogFile());
	final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
	rollingPolicy.setFileNamePattern(logConfig
			.getTransactionLogFileRotationPattern());
	rollingPolicy.setMaxHistory(logConfig.getMaxTransactionLogFileVersions());
	rollingPolicy.setCleanHistoryOnStart(false);
	rollingPolicy.setContext(loggerContext);
	rollingPolicy.setParent(fileAppender);
	rollingPolicy.start();
	fileAppender.setRollingPolicy(rollingPolicy);
	fileAppender.setTriggeringPolicy(rollingPolicy);
	fileAppender.start();

	final ch.qos.logback.classic.Logger logBackLogger = (ch.qos.logback.classic.Logger) transactionLog;
	logBackLogger.detachAndStopAllAppenders();
	logBackLogger.addAppender(fileAppender);
	logBackLogger.setLevel(Level.INFO);
	logBackLogger.setAdditive(false);

	this.writer = mapper.writer().without(
			SerializationFeature.INDENT_OUTPUT);
}
 
開發者ID:discoverydns,項目名稱:dnsapi-client,代碼行數:38,代碼來源:DefaultTransactionLogHandler.java

示例12: PhialLogger

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的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

示例13: init

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
private void init(FileLoggingSetup setup)
{
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();

    // 1) FileLoggingSetup - Encoder for File
    PatternLayoutEncoder encoder1 = new PatternLayoutEncoder();
    encoder1.setContext(lc);
    encoder1.setPattern(setup.mLogPattern);
    encoder1.start();

    // 2) FileLoggingSetup - rolling file appender
    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
    rollingFileAppender.setAppend(true);
    rollingFileAppender.setContext(lc);
    //rollingFileAppender.setFile(setup.mFolder + "/" + setup.mFileName + "." + setup.mFileExtension);

    // 3) FileLoggingSetup - Rolling policy (one log per day)
    TriggeringPolicy<ILoggingEvent> triggeringPolicy = null;
    switch (setup.mMode)
    {
        case DateFiles:
        {
            TimeBasedRollingPolicy timeBasedRollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
            timeBasedRollingPolicy.setFileNamePattern(setup.mFolder + "/" + setup.mFileName + "_%d{yyyyMMdd}." + setup.mFileExtension);
            timeBasedRollingPolicy.setMaxHistory(setup.mLogsToKeep);
            timeBasedRollingPolicy.setCleanHistoryOnStart(true);
            timeBasedRollingPolicy.setParent(rollingFileAppender);
            timeBasedRollingPolicy.setContext(lc);

            triggeringPolicy = timeBasedRollingPolicy;
            break;
        }
        case NumberedFiles:
        {
            FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
            fixedWindowRollingPolicy.setFileNamePattern(setup.mFolder + "/" + setup.mFileName + "%i." + setup.mFileExtension);
            fixedWindowRollingPolicy.setMinIndex(1);
            fixedWindowRollingPolicy.setMaxIndex(setup.mLogsToKeep);
            fixedWindowRollingPolicy.setParent(rollingFileAppender);
            fixedWindowRollingPolicy.setContext(lc);

            SizeBasedTriggeringPolicy<ILoggingEvent> sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy<>();
            sizeBasedTriggeringPolicy.setMaxFileSize(setup.mNumberedFileSizeLimit);

            triggeringPolicy = sizeBasedTriggeringPolicy;

            rollingFileAppender.setFile(FileLoggingUtil.getDefaultLogFile(setup));
            rollingFileAppender.setRollingPolicy(fixedWindowRollingPolicy);
            fixedWindowRollingPolicy.start();

            break;
        }
    }
    triggeringPolicy.start();

    rollingFileAppender.setTriggeringPolicy(triggeringPolicy);
    rollingFileAppender.setEncoder(encoder1);
    rollingFileAppender.start();

    // add the newly created appenders to the root logger;
    // qualify Logger to disambiguate from org.slf4j.Logger
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) mLogger;
    root.detachAndStopAllAppenders();
    root.addAppender(rollingFileAppender);
}
 
開發者ID:MFlisar,項目名稱:Lumberjack,代碼行數:67,代碼來源:FileLoggingTree.java

示例14: initLog

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
private void initLog(){
    final File logDir = getLogDir();
    final File logFile = new File(logDir, "chaincloud-v.log");
    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    final PatternLayoutEncoder filePattern = new PatternLayoutEncoder();
    filePattern.setContext(context);
    filePattern.setPattern("%d{HH:mm:ss.SSS} [%thread] %logger{0} - %msg%n");
    filePattern.start();

    final RollingFileAppender<ILoggingEvent> fileAppender = new
            RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(context);
    fileAppender.setFile(logFile.getAbsolutePath());

    final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new
            TimeBasedRollingPolicy<ILoggingEvent>();
    rollingPolicy.setContext(context);
    rollingPolicy.setParent(fileAppender);
    rollingPolicy.setFileNamePattern(logDir.getAbsolutePath() + "/chaincloud-v.%d.log.gz");
    rollingPolicy.setMaxHistory(7);
    rollingPolicy.start();

    fileAppender.setEncoder(filePattern);
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.start();

    final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
    logcatTagPattern.setContext(context);
    logcatTagPattern.setPattern("%logger{0}");
    logcatTagPattern.start();

    final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder();
    logcatPattern.setContext(context);
    logcatPattern.setPattern("[%thread] %msg%n");
    logcatPattern.start();

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

    final ch.qos.logback.classic.Logger log = context.getLogger(Logger.ROOT_LOGGER_NAME);
    log.addAppender(fileAppender);
    log.addAppender(logcatAppender);
    log.setLevel(Level.INFO);
}
 
開發者ID:chaincloud-dot-com,項目名稱:chaincloud-v,代碼行數:48,代碼來源:ChainCloudVApplication.java

示例15: initLogging

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; //導入方法依賴的package包/類
private void initLogging()
{
    final File logDir = getDir("log", Constants.TEST ? Context.MODE_WORLD_READABLE : MODE_PRIVATE);
    final File logFile = new File(logDir, "wallet.log");

    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

    final PatternLayoutEncoder filePattern = new PatternLayoutEncoder();
    filePattern.setContext(context);
    filePattern.setPattern("%d{HH:mm:ss.SSS} [%thread] %logger{0} - %msg%n");
    filePattern.start();

    final RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(context);
    fileAppender.setFile(logFile.getAbsolutePath());

    final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
    rollingPolicy.setContext(context);
    rollingPolicy.setParent(fileAppender);
    rollingPolicy.setFileNamePattern(logDir.getAbsolutePath() + "/wallet.%d.log.gz");
    rollingPolicy.setMaxHistory(7);
    rollingPolicy.start();

    fileAppender.setEncoder(filePattern);
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.start();

    final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
    logcatTagPattern.setContext(context);
    logcatTagPattern.setPattern("%logger{0}");
    logcatTagPattern.start();

    final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder();
    logcatPattern.setContext(context);
    logcatPattern.setPattern("[%thread] %msg%n");
    logcatPattern.start();

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

    final ch.qos.logback.classic.Logger log = context.getLogger(Logger.ROOT_LOGGER_NAME);
    log.addAppender(fileAppender);
    log.addAppender(logcatAppender);
    log.setLevel(Level.INFO);
}
 
開發者ID:soapboxsys,項目名稱:ombuds-android,代碼行數:49,代碼來源:WalletApplication.java


注:本文中的ch.qos.logback.core.rolling.TimeBasedRollingPolicy.setMaxHistory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。