本文整理汇总了Java中ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy.setContext方法的典型用法代码示例。如果您正苦于以下问题:Java SizeBasedTriggeringPolicy.setContext方法的具体用法?Java SizeBasedTriggeringPolicy.setContext怎么用?Java SizeBasedTriggeringPolicy.setContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy
的用法示例。
在下文中一共展示了SizeBasedTriggeringPolicy.setContext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureFileLogging
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; //导入方法依赖的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;
}
示例2: configureFileLogging
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; //导入方法依赖的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;
}
示例3: createLogAppender
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; //导入方法依赖的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;
}
示例4: createTriggeringPolicy
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; //导入方法依赖的package包/类
@Override
public TriggeringPolicy<ILoggingEvent> createTriggeringPolicy(LoggerContext context) {
SizeBasedTriggeringPolicy<ILoggingEvent> policy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
if (fileSize != null && fileSize.length() > 0) {
policy.setMaxFileSize(FileSize.valueOf(fileSize));
}
policy.setContext(context);
return policy;
}
示例5: configureLogger
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; //导入方法依赖的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);
}
示例6: createAppender
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; //导入方法依赖的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;
}
示例7: configureRotatingLogging
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; //导入方法依赖的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();
}
}