當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。