本文整理汇总了Java中ch.qos.logback.core.rolling.FixedWindowRollingPolicy.setMinIndex方法的典型用法代码示例。如果您正苦于以下问题:Java FixedWindowRollingPolicy.setMinIndex方法的具体用法?Java FixedWindowRollingPolicy.setMinIndex怎么用?Java FixedWindowRollingPolicy.setMinIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.rolling.FixedWindowRollingPolicy
的用法示例。
在下文中一共展示了FixedWindowRollingPolicy.setMinIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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();
}
示例5: 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);
}
示例6: 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);
}
示例7: 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;
}
示例8: 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);*/
}
示例9: 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();
}
}
示例10: 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);
}