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


Java RollingFileAppender.setPrudent方法代码示例

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


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

示例1: setupLogger

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

示例2: buildLoggerContext

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
static LoggerContext buildLoggerContext(String stamp, String filename,
    boolean safetyMode) {
  LoggerContext loggerContext = new LoggerContext();

  RollingFileAppender<ILoggingEvent> rfa = new RollingFileAppender<ILoggingEvent>();
  PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
  patternLayout.setPattern(stamp + " %5p - %-50m%n");
  patternLayout.setContext(loggerContext);
  patternLayout.start();

  rfa.setEncoder(patternLayout);
  
  rfa.setAppend(true);
  rfa.setPrudent(safetyMode);
  rfa.setContext(loggerContext);

  TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
  
  tbrp.setContext(loggerContext);
  tbrp.setFileNamePattern(filename+"-%d{"+DATE_PATTERN+"}.log");
  tbrp.setParent(rfa);
  tbrp.start();

  rfa.setRollingPolicy(tbrp);

  
  rfa.start();

  ch.qos.logback.classic.Logger root = loggerContext
      .getLogger(Logger.ROOT_LOGGER_NAME);
  root.addAppender(rfa);

  return loggerContext;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:35,代码来源:SafeModeRollingFileAppender.java

示例3: DefaultTransactionLogHandler

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

示例4: dynamic

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
private static Logger dynamic(String name, LogLevel level) {
	// ( LoggerContext ) LoggerFactory.getILoggerFactory();
	/*
	 * String thName = Thread.currentThread().getName(); if( thName != null
	 * && !thName.trim().isEmpty() ) name = name + "_" +
	 * thName.trim().replaceAll( " ", "_" );
	 */
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	encoder.setPattern("%d{HH:mm:ss.SSS} [%thread][%-5level][%logger{36}] - %msg%n");
	encoder.setContext(context);
	encoder.setCharset(Charset.forName("UTF-8"));

	DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent> timeBasedTriggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent>();
	timeBasedTriggeringPolicy.setContext(context);

	TimeBasedRollingPolicy<ILoggingEvent> timeBasedRollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
	timeBasedRollingPolicy.setContext(context);
	String workspace = System.getenv("WORKSPACE");
	if (workspace == null)
		workspace = "";
	if (!workspace.isEmpty() && !workspace.endsWith("/"))
		workspace += "/";
	timeBasedRollingPolicy.setFileNamePattern(workspace + "logs/" + name + "-%d{yyyy-MM-dd}.log");
	timeBasedRollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(timeBasedTriggeringPolicy);

	timeBasedTriggeringPolicy.setTimeBasedRollingPolicy(timeBasedRollingPolicy);

	RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
	rollingFileAppender.setAppend(false);
	rollingFileAppender.setContext(context);
	rollingFileAppender.setEncoder(encoder);
	rollingFileAppender.setFile("logs/" + name + ".log");
	rollingFileAppender.setName(name + "Appender");
	rollingFileAppender.setPrudent(true); // set to true to release the hold
											// of log files.
	rollingFileAppender.setRollingPolicy(timeBasedRollingPolicy);
	rollingFileAppender.setTriggeringPolicy(timeBasedTriggeringPolicy);

	timeBasedRollingPolicy.setParent(rollingFileAppender);

	encoder.start();
	timeBasedRollingPolicy.start();

	rollingFileAppender.stop();
	rollingFileAppender.start();

	Logger logger = context.getLogger(name);
	logger.setLevel(level.convert());
	logger.setAdditive(false);
	logger.addAppender(rollingFileAppender);

	return logger;
}
 
开发者ID:slimsymphony,项目名称:testgrid,代码行数:54,代码来源:LogUtils.java


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