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


Java FixedWindowRollingPolicy.setFileNamePattern方法代码示例

本文整理汇总了Java中ch.qos.logback.core.rolling.FixedWindowRollingPolicy.setFileNamePattern方法的典型用法代码示例。如果您正苦于以下问题:Java FixedWindowRollingPolicy.setFileNamePattern方法的具体用法?Java FixedWindowRollingPolicy.setFileNamePattern怎么用?Java FixedWindowRollingPolicy.setFileNamePattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.core.rolling.FixedWindowRollingPolicy的用法示例。


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

示例1: fileAppender

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的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: configureFileLogging

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
private static OutputStreamAppender<ILoggingEvent> configureFileLogging(File logFile, LoggerContext loggerContext) {
    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
    rollingFileAppender.setFile(logFile.getAbsolutePath());
    rollingFileAppender.setName("com.documents4j.logger.client.file");
    rollingFileAppender.setContext(loggerContext);
    FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
    fixedWindowRollingPolicy.setFileNamePattern(logFile.getAbsolutePath() + ".%i.gz");
    fixedWindowRollingPolicy.setMaxIndex(LogDescription.MAXIMUM_LOG_HISTORY_INDEX);
    fixedWindowRollingPolicy.setContext(loggerContext);
    fixedWindowRollingPolicy.setParent(rollingFileAppender);
    SizeBasedTriggeringPolicy<ILoggingEvent> sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
    sizeBasedTriggeringPolicy.setMaxFileSize(LogDescription.MAXIMUM_LOG_FILE_SIZE);
    sizeBasedTriggeringPolicy.setContext(loggerContext);
    rollingFileAppender.setRollingPolicy(fixedWindowRollingPolicy);
    rollingFileAppender.setTriggeringPolicy(sizeBasedTriggeringPolicy);
    sizeBasedTriggeringPolicy.start();
    fixedWindowRollingPolicy.start();
    System.out.println("Logging: The log is written to " + logFile);
    return rollingFileAppender;
}
 
开发者ID:documents4j,项目名称:documents4j,代码行数:21,代码来源:StandaloneClient.java

示例3: configureFileLogging

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
private static OutputStreamAppender<ILoggingEvent> configureFileLogging(File logFile, LoggerContext loggerContext) {
    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
    rollingFileAppender.setFile(logFile.getAbsolutePath());
    rollingFileAppender.setName("com.documents4j.logger.server.file");
    rollingFileAppender.setContext(loggerContext);
    FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
    fixedWindowRollingPolicy.setFileNamePattern(logFile.getAbsolutePath() + ".%i.gz");
    fixedWindowRollingPolicy.setMaxIndex(LogDescription.MAXIMUM_LOG_HISTORY_INDEX);
    fixedWindowRollingPolicy.setContext(loggerContext);
    fixedWindowRollingPolicy.setParent(rollingFileAppender);
    SizeBasedTriggeringPolicy<ILoggingEvent> sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
    sizeBasedTriggeringPolicy.setMaxFileSize(LogDescription.MAXIMUM_LOG_FILE_SIZE);
    sizeBasedTriggeringPolicy.setContext(loggerContext);
    rollingFileAppender.setRollingPolicy(fixedWindowRollingPolicy);
    rollingFileAppender.setTriggeringPolicy(sizeBasedTriggeringPolicy);
    sizeBasedTriggeringPolicy.start();
    fixedWindowRollingPolicy.start();
    System.out.println("Logging: The log is written to " + logFile);
    return rollingFileAppender;
}
 
开发者ID:documents4j,项目名称:documents4j,代码行数:21,代码来源:StandaloneServer.java

示例4: createLogAppender

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
/**
 * Create an appender that will roll over based on size
 * 
 * @param context
 * @param encoder
 * @return An appender that matches the set up of the logger builder
 */
private RollingFileAppender<ILoggingEvent> createLogAppender(LoggerContext context, Encoder<ILoggingEvent> encoder){
	RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
	appender.setEncoder(encoder);
	appender.setFile(file);
	
	FixedWindowRollingPolicy rolling = new FixedWindowRollingPolicy();
	rolling.setParent(appender);
	rolling.setContext(context);

	//Set the maximum number of logs, either to the user specified setting or default to 1
	rolling.setMinIndex(1);
	if (maxNumberLogs.isPresent() && maxNumberLogs.get() >= 0) {
		rolling.setMaxIndex(maxNumberLogs.get());
	} else {
		rolling.setMaxIndex(1);
	}
	rolling.setFileNamePattern(getFileWithPattern("%i"));

	//Configure size based rolling
	SizeBasedTriggeringPolicy<ILoggingEvent> trigger = new SizeBasedTriggeringPolicy<>();
	trigger.setMaxFileSize(getMaxFileSize());
	trigger.setContext(context);

	rolling.start();
	trigger.start();
	appender.setRollingPolicy(rolling);
	appender.setTriggeringPolicy(trigger);
	
	return appender;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:38,代码来源:BaleenFileLoggerBuilder.java

示例5: instantiatePolicy

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
@Override
protected FixedWindowRollingPolicy instantiatePolicy(LoggerContext context) {
	FixedWindowRollingPolicy policy = new FixedWindowRollingPolicy();
	policy.setFileNamePattern(getFileNamePattern());
	if (getHistorySize() > 0) {
		policy.setMinIndex(1);
		policy.setMaxIndex(getHistorySize());
	}
	policy.setContext(context);
	return policy;
}
 
开发者ID:bootique,项目名称:bootique-logback,代码行数:12,代码来源:FixedWindowPolicyFactory.java

示例6: getFileAppender

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
/**
 * Creates the file appender for the logger with a custom logging policy
 * (RollingFileAppender with max size of 1 MB and up to 3 backups)
 * @param logFile the file to log into
 * @return the FileAppender for the specified File and current logging
 *         context
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected static FileAppender getFileAppender(File logFile) {
    // init rolling file appender
    RollingFileAppender rfAppender = new RollingFileAppender();
    rfAppender.setContext(lc);
    rfAppender.setFile(logFile.getAbsolutePath());
    rfAppender.setAppend(true);

    // rolling policy: keep up to 3 rollover-files with postfix .%i.log
    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setContext(lc);
    rollingPolicy.setParent(rfAppender);
    rollingPolicy.setFileNamePattern(logFileName + ".%i.log");
    rollingPolicy.setMinIndex(1);
    rollingPolicy.setMaxIndex(3);
    rollingPolicy.start();

    // rollover after logfixe exceeds 1MB
    SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
    triggeringPolicy.setMaxFileSize(FileSize.valueOf("1mb"));
    triggeringPolicy.start();

    // layout of the log entries
    Encoder encoder = getDefaultEncoder();

    // apply settings and start appender
    rfAppender.setEncoder(encoder);
    rfAppender.setRollingPolicy(rollingPolicy);
    rfAppender.setTriggeringPolicy(triggeringPolicy);
    rfAppender.start();

    return rfAppender;
}
 
开发者ID:klamann,项目名称:maps4cim,代码行数:41,代码来源:LoggerConfig.java

示例7: initLogback

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
/**
 * Initialize Logback
 */
private static void initLogback() {
    // reset logger context
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    
    // shared console appender
    ConsoleAppender.setContext(context);
    ConsoleAppender.setTarget("System.out");
    
    PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder();
    consoleEncoder.setContext(context);
    consoleEncoder.setPattern(LogPattern);
    consoleEncoder.start();
    ConsoleAppender.setEncoder(consoleEncoder);
    ConsoleAppender.start();
    
    // rolling file
    String logFile = getFilePath() + File.separatorChar + getFileName();
    FileAppender.setContext(context);
    FileAppender.setFile(logFile);
    
    // log pattern
    PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
    fileEncoder.setContext(context);
    fileEncoder.setPattern(LogPattern);
    fileEncoder.start();
    FileAppender.setEncoder(fileEncoder);
    
    // rolling policy
    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setContext(context);
    rollingPolicy.setParent(FileAppender);
    rollingPolicy.setFileNamePattern(logFile + "%i.zip");
    rollingPolicy.setMinIndex(1);
    rollingPolicy.setMaxIndex(1);
    rollingPolicy.start();
    
    // file max size - if fileLimit is 0, set max file size to maximum allowed
    long fileLimit = getFileLimitInKBytes() != 0 ? getFileLimitInKBytes() * 1024 : Long.MAX_VALUE;
    SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>(String.valueOf(fileLimit));
    triggeringPolicy.start();
    
    FileAppender.setRollingPolicy(rollingPolicy);
    FileAppender.setTriggeringPolicy(triggeringPolicy);
    FileAppender.start();
}
 
开发者ID:RicardoJTSantos,项目名称:ScriptAgentNewRelicPlugin,代码行数:50,代码来源:Logger.java

示例8: init

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的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

示例9: configureLogger

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
private void configureLogger() {
    File targetFile = new File(LOGFILE_PATH);

    // reset the default context (which may already have been initialized)
    // since we want to reconfigure it
    LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
    lc.reset();

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(lc);
    encoder.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} : %-5level : %msg%n");
    encoder.start();

    String filePattern = targetFile.getParent() + "/" + targetFile.getName() + ".%i.zip";
    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setFileNamePattern(filePattern);
    rollingPolicy.setMinIndex(1);
    rollingPolicy.setMaxIndex(3);
    rollingPolicy.setContext(lc);

    SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
    triggeringPolicy.setMaxFileSize("5MB");
    triggeringPolicy.setContext(lc);

    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
    rollingFileAppender.setAppend(true);
    rollingFileAppender.setName("FILE");
    rollingFileAppender.setContext(lc);
    rollingFileAppender.setFile(LOGFILE_PATH);
    rollingFileAppender.setRollingPolicy(rollingPolicy);
    rollingFileAppender.setTriggeringPolicy(triggeringPolicy);
    rollingFileAppender.setEncoder(encoder);

    triggeringPolicy.start();
    rollingPolicy.setParent(rollingFileAppender);
    rollingPolicy.start();
    rollingFileAppender.start();

    // Logcat appender
    LogcatAppender logcatAppender = new LogcatAppender();
    logcatAppender.setContext(lc);
    logcatAppender.setName("LOGCAT");
    logcatAppender.setEncoder(encoder);
    logcatAppender.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) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.ALL);
    root.addAppender(rollingFileAppender);
    root.addAppender(logcatAppender);
}
 
开发者ID:andischerer,项目名称:cordova-plugin-logtofile,代码行数:53,代码来源:LogToFile.java

示例10: LogConfigurator

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
public LogConfigurator(File f) {

            Appender appender = null;

            if (f != null) {
                try {
                    String line = Files.readFirstLine(f, Charset.defaultCharset()).trim();
                    switch (line) {
                        case "rolling":
                            String logFile = workingDirectory();
                            message = ("rolling to file://{}" + logFile);

                            RollingFileAppender r = new RollingFileAppender();
                            r.setFile(logFile);
                            r.setAppend(true);

                            SizeBasedTriggeringPolicy triggeringPolicy = new ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy();
                            triggeringPolicy.setMaxFileSize(FileSize.valueOf("5MB"));
                            triggeringPolicy.start();

                            FixedWindowRollingPolicy policy = new FixedWindowRollingPolicy();
                            policy.setFileNamePattern("log.%i.gz");
                            policy.setParent(r);
                            policy.setContext(LOG.getLoggerContext());
                            policy.start();

                            r.setEncoder(logEncoder());
                            r.setRollingPolicy(policy);
                            r.setTriggeringPolicy(triggeringPolicy);


                            appender = r;
                            break;
                        //TODO TCP/UDP etc
                    }
                } catch (IOException e) {
                    logger.error("{}", e);
                    appender = null;
                }
            }

            if (appender == null) {
                //default
                ConsoleAppender a = new ConsoleAppender();
                a.setEncoder(logEncoder());
                appender = a;
                message = "ConsoleAppender";
            }


            LOG.detachAndStopAllAppenders();

            appender.setContext(LOG.getLoggerContext());
            appender.start();

            LOG.addAppender(appender);


            this.appender = appender;
        }
 
开发者ID:automenta,项目名称:spimedb,代码行数:61,代码来源:Main.java

示例11: createAppender

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
/**
 * Creates an {@link OutputStreamAppender} for the required filter, pattern and logger output.
 *
 * @param context Logger context to associate the appender with.
 * @param filter Event log filter.
 * @param logOutput Logger output information for the destination to write logger events to.
 * @param patternProperty Logger context property that defines the pattern for formatting logger event output.
 * @param name The name of the appender.
 * @return An {@link OutputStreamAppender} for the required parameters.
 */
private static OutputStreamAppender<ILoggingEvent> createAppender(LoggerContext context, Filter<ILoggingEvent> filter, LoggerOutput logOutput, String patternProperty, String name) {
  final PatternLayoutEncoder patternLayoutEncoder = createPatternLayoutEncoder(context, patternProperty);
  final OutputStreamAppender<ILoggingEvent> appender;
  if (logOutput.isConsole()) {
    appender = new OutputStreamAppender<>();
    appender.setContext(context);
    appender.setEncoder(patternLayoutEncoder);
    appender.setOutputStream(logOutput.getPrintStream());
    appender.setName(name);
    appender.addFilter(filter);
    appender.start();
  } else {
    RollingFileAppender<ILoggingEvent> rAppender = new RollingFileAppender<>();
    rAppender.setContext(context);
    rAppender.setEncoder(patternLayoutEncoder);
    rAppender.setFile(logOutput.getOutputName()+"."+logOutput.getOutputType());
    rAppender.setName(name);
    rAppender.addFilter(filter);

    final FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setContext(context);
    rollingPolicy.setParent(rAppender);
    rollingPolicy.setFileNamePattern(logOutput.getOutputName()+"%i"+"."+logOutput.getOutputType());
    rollingPolicy.setMinIndex(1);
    rollingPolicy.setMaxIndex(logOutput.getFileCount());
    rollingPolicy.start();

    final SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<>();
    triggeringPolicy.setContext(context);
    triggeringPolicy.setMaxFileSize(logOutput.getFileLimit());
    triggeringPolicy.start();

    rAppender.setRollingPolicy(rollingPolicy);
    rAppender.setTriggeringPolicy(triggeringPolicy);
    rAppender.start();

    appender = rAppender;
  }
  return appender;
}
 
开发者ID:mqlight,项目名称:java-mqlight,代码行数:51,代码来源:LogbackLoggingImpl.java

示例12: setup

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
public static void setup(String fileName) {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setFile(fileName + ".log");

    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setContext(loggerContext);
    rollingPolicy.setParent(appender);
    rollingPolicy.setFileNamePattern(fileName + "_%i.log");
    rollingPolicy.setMinIndex(1);
    rollingPolicy.setMaxIndex(10);
    rollingPolicy.start();

    SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
    triggeringPolicy.setMaxFileSize(FileSize.valueOf("10MB"));
    triggeringPolicy.start();

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n");
    encoder.start();

    //noinspection unchecked
    appender.setEncoder(encoder);
    appender.setRollingPolicy(rollingPolicy);
    //noinspection unchecked
    appender.setTriggeringPolicy(triggeringPolicy);
    appender.start();

    logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    //noinspection unchecked
    logbackLogger.addAppender(appender);
    logbackLogger.setLevel(Level.INFO);

    // log errors in separate file
    // not working as expected still.... damn logback...
   /* FileAppender errorAppender = new FileAppender();
    errorAppender.setEncoder(encoder);
    errorAppender.setName("Error");
    errorAppender.setContext(loggerContext);
    errorAppender.setFile(fileName + "_error.log");
    LevelFilter levelFilter = new LevelFilter();
    levelFilter.setLevel(Level.ERROR);
    levelFilter.setOnMatch(FilterReply.ACCEPT);
    levelFilter.setOnMismatch(FilterReply.DENY);
    levelFilter.start();
    errorAppender.addFilter(levelFilter);
    errorAppender.start();
    logbackLogger.addAppender(errorAppender);*/
}
 
开发者ID:bisq-network,项目名称:exchange,代码行数:53,代码来源:Log.java

示例13: configureRotatingLogging

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
public static void configureRotatingLogging( String baseLoggingDir, String loglevel, String appName ) {
    
    if ( !baseLoggingDir.endsWith( "/" ) ) {
        baseLoggingDir = baseLoggingDir + "/";
    }
    
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();
    Logger rootLogger = getRootLogger( loglevel );
    PatternLayoutEncoder ple = getPatternLayoutEncoder( lc );
    
    String baseAppLoggingDir = baseLoggingDir;
    // set a system property so other loggers write the correct place
    System.setProperty( "krux-base-app-log-dir", baseAppLoggingDir );

    try {
        // Define file appender with layout and output log file name
        RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
        fileAppender.setContext( lc );
        fileAppender.setName( "krux-file-appender" );
        fileAppender.setFile( baseAppLoggingDir + appName + ".log" );
        fileAppender.setAppend( true );
        fileAppender.setEncoder( ple );
        
        FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
        rollingPolicy.setContext( lc );
        rollingPolicy.setMinIndex( 1 );
        rollingPolicy.setMaxIndex( 9 );
        rollingPolicy.setFileNamePattern( baseAppLoggingDir + appName + ".%i.log.gz" );
        rollingPolicy.setParent( fileAppender );
        rollingPolicy.start();
        
        SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>( "100MB" );
        triggeringPolicy.setContext( lc );
        triggeringPolicy.start();

        fileAppender.setRollingPolicy( rollingPolicy );
        fileAppender.setTriggeringPolicy( triggeringPolicy );
        fileAppender.start();

        // Wrap the console appenders in an async appenders
        AsyncAppender asyncOut = new AsyncAppender();
        asyncOut.setContext( lc );
        asyncOut.setDiscardingThreshold( 0 );
        asyncOut.setQueueSize( 500 );
        asyncOut.addAppender( fileAppender );
        asyncOut.setName( "stdlib-async-out" );
        asyncOut.start();

        // Add the appender to root logger
        rootLogger.addAppender( asyncOut );
        
        // wrap stdout & stderr in log4j appenders 
        StdOutErrLog.tieSystemOutAndErrToLog();
        
    } catch ( Exception e ) {
        System.out.println( "Failed to add appender !!" );
        e.printStackTrace();
    }

}
 
开发者ID:krux,项目名称:java-stdlib,代码行数:62,代码来源:LoggerConfigurator.java

示例14: startFileLogging

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
/**
 *
 * @param logFilePath
 */
public static void startFileLogging(String logFilePath) {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    LoggerContext loggerContext = rootLogger.getLoggerContext();

    RollingFileAppender<ILoggingEvent> rfAppender = new RollingFileAppender<>();
    rfAppender.setContext(loggerContext);
    rfAppender.setFile(logFilePath);

    FixedWindowRollingPolicy fwRollingPolicy = new FixedWindowRollingPolicy();
    fwRollingPolicy.setContext(loggerContext);
    fwRollingPolicy.setFileNamePattern(logFilePath + "-%i.log.zip");
    fwRollingPolicy.setParent(rfAppender);
    fwRollingPolicy.start();

    SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<>();
    triggeringPolicy.setMaxFileSize(FileSize.valueOf("5 mb"));
    triggeringPolicy.start();

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %highlight(%-5level) %logger{36} - %msg%n");
    encoder.start();

    rfAppender.setEncoder(encoder);
    rfAppender.setName("ROLLINGFILE");
    rfAppender.setRollingPolicy(fwRollingPolicy);
    rfAppender.setTriggeringPolicy(triggeringPolicy);
    rfAppender.start();

    AsyncAppender asyncAppender = new AsyncAppender();
    asyncAppender.setContext(loggerContext);
    asyncAppender.setName("ASYNC");
    asyncAppender.setQueueSize(ASYNC_QUEUE_SIZE);
    asyncAppender.setMaxFlushTime(ASYNC_MAX_FLUSH_TIME);
    asyncAppender.addAppender(rfAppender);
    asyncAppender.start();

    rootLogger.addAppender(asyncAppender);
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:45,代码来源:LoggingInitializer.java

示例15: configureLogback

import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; //导入方法依赖的package包/类
private void configureLogback() {
	    // reset the default context (which may already have been initialized)
	    // since we want to reconfigure it
	    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
	    context.reset();

	    final String LOG_DIR = getExternalFilesDir(null).getAbsolutePath();

	    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
	    rollingFileAppender.setAppend(true);
	    rollingFileAppender.setContext(context);

	    // OPTIONAL: Set an active log file (separate from the rollover files).
	    // If rollingPolicy.fileNamePattern already set, you don't need this.
	    rollingFileAppender.setFile(LOG_DIR + "/most.log");

	    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
	    rollingPolicy.setFileNamePattern(LOG_DIR + "/most.%i.log");
	    rollingPolicy.setMinIndex(1);
	    rollingPolicy.setMaxIndex(2);
	    rollingPolicy.setParent(rollingFileAppender);  // parent and context required!
	    rollingPolicy.setContext(context);
	    rollingPolicy.start();

	    rollingFileAppender.setRollingPolicy(rollingPolicy);
	    
	    SizeBasedTriggeringPolicy<ILoggingEvent> triggerPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
	    triggerPolicy.setMaxFileSize("10MB");
	    
	    rollingFileAppender.setTriggeringPolicy(triggerPolicy);
	    
	    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	    encoder.setPattern("%date [%thread] %-5level %logger{36}.%method - %msg%n");
	    encoder.setContext(context);
	    encoder.start();

	    rollingFileAppender.setEncoder(encoder);
	    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) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
//	    root.setLevel(Level.DEBUG);
//	    root.addAppender(rollingFileAppender);
	    
	    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.most");
	    logger.setLevel(Level.DEBUG);
	    logger.addAppender(rollingFileAppender);
	    
	    // print any status messages (warnings, etc) encountered in logback config
	    StatusPrinter.print(context);
	}
 
开发者ID:participactunibo,项目名称:MoST,代码行数:53,代码来源:MoSTApplication.java


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