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


Java RollingFileAppender類代碼示例

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


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

示例1: fileAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config,
		String logFile) {
	RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	String logPattern = this.patterns.getProperty("file", FILE_LOG_PATTERN);
	encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
	appender.setEncoder(encoder);
	config.start(encoder);

	appender.setFile(logFile);

	FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
	rollingPolicy.setFileNamePattern(logFile + ".%i");
	appender.setRollingPolicy(rollingPolicy);
	rollingPolicy.setParent(appender);
	config.start(rollingPolicy);

	SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
	triggeringPolicy.setMaxFileSize("10MB");
	appender.setTriggeringPolicy(triggeringPolicy);
	config.start(triggeringPolicy);

	config.appender("FILE", appender);
	return appender;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:26,代碼來源:DefaultLogbackConfiguration.java

示例2: startLogback

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
public static void startLogback() {
    long startTime = System.nanoTime();
    Config config = Configs.DEFAULT.logging();
    LogbackConfig logbackConfig = getLogbackConfig(config);
    LogbackManager logbackMgr = LogbackManager.INSTANCE;
    RollingFileAppender<ILoggingEvent> fileAppender = logbackMgr.createRollingFileAppender(logbackConfig);
    ConsoleAppender<ILoggingEvent> consoleAppender = logbackMgr
            .createConsoleAppender(APPENDER_CONSOLE, config.getString(KEY_LOG_PATTERN_CONSOLE));
    List<Appender<ILoggingEvent>> appenderList = new ArrayList<>();
    appenderList.add(consoleAppender);
    appenderList.add(fileAppender);
    logbackMgr.getAppenders().addAll(appenderList);
    LoggerContext context = logbackMgr.getLoggerContext();
    initRootLogger(context, consoleAppender, config);
    addLoggers(config, appenderList);
    addAsyncAppender(config, fileAppender);
    context.start();
    context.getLogger(LogbackInitializer.class).info(INIT_MSG, elapsedMillis(startTime));
}
 
開發者ID:AdeptJ,項目名稱:adeptj-runtime,代碼行數:20,代碼來源:LogbackInitializer.java

示例3: get

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
public static final MetasfreshFileLoggerHelper get(final LoggerContext context)
{
	final Logger rootLogger = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
	final Appender<ILoggingEvent> appender = rootLogger.getAppender(FILEAPPENDER_NAME);
	if (!(appender instanceof RollingFileAppender))
	{
		return NULL;
	}

	final RollingFileAppender<?> rollingFileAppender = (RollingFileAppender<?>)appender;
	final RollingPolicy rollingPolicy = rollingFileAppender.getRollingPolicy();
	if (!(rollingPolicy instanceof MetasfreshTimeBasedRollingPolicy))
	{
		return NULL;
	}

	final MetasfreshTimeBasedRollingPolicy<?> metasfreshRollingPolicy = (MetasfreshTimeBasedRollingPolicy<?>)rollingPolicy;

	return new MetasfreshFileLoggerHelper(rollingFileAppender, metasfreshRollingPolicy);
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:21,代碼來源:MetasfreshFileLoggerHelper.java

示例4: getLogger

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
public Logger getLogger() {
    LoggerContext  context = (LoggerContext)LoggerFactory.getILoggerFactory();
    Logger rootLogger = context.getLogger("ROOT");
    rootLogger.detachAppender("console");

    // Just a simple pattern for outputting the messages, includes the ISO8601 formatted timestamp and marker.
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%msg");
    encoder.start();

    RollingFileAppender appender = new RollingFileAppender<>();
    appender.setContext(context);
    appender.setRollingPolicy(new ExternalRotateRollingPolicy());
    appender.getRollingPolicy().setParent(appender);
    appender.setFile(new File(folder.getRoot(), "log").getAbsolutePath());

    appender.setEncoder(encoder);
    appender.start();
    rootLogger.addAppender(appender);
    context.start();
    return rootLogger;

}
 
開發者ID:ezbake,項目名稱:ezbake-common-java,代碼行數:25,代碼來源:TestExternalRotateRollingPolicy.java

示例5: buildAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
protected Appender buildAppender(String name, String fileName, String pattern) {
    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.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    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,代碼行數:25,代碼來源:DynamicLogbackLogger.java

示例6: buildDailyMaxRollingAppender

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

示例7: buildAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
protected Appender buildAppender(String name, String fileName, String pattern) {
    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.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    rolling.setContext(loggerContext);
    rolling.start();
    appender.setRollingPolicy(rolling);

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

示例8: buildDailyMaxRollingAppender

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

示例9: buildAppender

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

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    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,代碼行數:20,代碼來源:DynamicLogbackLogger.java

示例10: buildDailyMaxRollingAppender

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

示例11: createRollingFileAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
protected FileAppender<ILoggingEvent> createRollingFileAppender(Encoder<ILoggingEvent> encoder,
                                                                LoggerContext context,
                                                                RollingPolicyFactory rollingPolicy) {

    RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
    appender.setFile(file);
    appender.setContext(context);
    appender.setEncoder(encoder);
    // Setup rolling policy
    RollingPolicy policy = rollingPolicy.createRollingPolicy(context);
    appender.setRollingPolicy(policy);
    policy.setParent(appender);
    // Setup triggering policy
    TriggeringPolicy<ILoggingEvent> triggeringPolicy = rollingPolicy.createTriggeringPolicy(context);
    if (triggeringPolicy != null) {
        appender.setTriggeringPolicy(triggeringPolicy);
        triggeringPolicy.start();
    }
    policy.start();
    appender.start();

    return appender;
}
 
開發者ID:bootique,項目名稱:bootique-logback,代碼行數:24,代碼來源:FileAppenderFactory.java

示例12: setUp

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);

    final RollingFileAppender<LoggingEvent> fileAppender = new RollingFileAppender<>();
    fileAppender.setFile("application.log");

    final TimeBasedRollingPolicy<LoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>();
    _context = new LoggerContext();

    _triggeringPolicy = new SizeAndRandomizedTimeBasedFNATP<>(_wrappedPolicy);
    rollingPolicy.setContext(_context);
    rollingPolicy.setFileNamePattern("application-%d{yyyy-MM-dd_HH}.log");
    rollingPolicy.setParent(fileAppender);
    rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(_triggeringPolicy);
    rollingPolicy.start();
}
 
開發者ID:ArpNetworking,項目名稱:logback-steno,代碼行數:18,代碼來源:SizeAndRandomizedTimeBasedFNATPTest.java

示例13: addFileAppender

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

示例14: getAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
private FileAppender<ILoggingEvent> getAppender(String pluginId) {
    File pluginLogFileLocation = pluginLogFile(pluginId);

    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
    rollingFileAppender.setEncoder(LogHelper.encoder());
    rollingFileAppender.setContext(LogHelper.LOGGER_CONTEXT);
    rollingFileAppender.setFile(pluginLogFileLocation.getPath());
    rollingFileAppender.setName(rollingFileAppenderName(pluginId));

    LogHelper.rollingPolicyForAppender(
            rollingFileAppender,
            "5 MB",
            "20 MB",
            7
    );

    rollingFileAppender.start();
    return rollingFileAppender;
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:20,代碼來源:DefaultPluginLoggingService.java

示例15: rollingAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //導入依賴的package包/類
private RollingFileAppender<ILoggingEvent> rollingAppender(String file) throws IOException {
    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
    rollingFileAppender.setEncoder(LogHelper.encoder("%date{ISO8601} - %msg%n"));
    rollingFileAppender.setContext(LogHelper.LOGGER_CONTEXT);
    rollingFileAppender.setFile(getEffectiveLogDirectory(file));
    rollingFileAppender.setName(UUID.randomUUID().toString());

    LogHelper.rollingPolicyForAppender(
            rollingFileAppender,
            "5 MB",
            "20 MB",
            4
    );
    rollingFileAppender.start();
    return rollingFileAppender;
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:17,代碼來源:AgentOutputAppender.java


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