當前位置: 首頁>>代碼示例>>Java>>正文


Java Logger.detachAndStopAllAppenders方法代碼示例

本文整理匯總了Java中ch.qos.logback.classic.Logger.detachAndStopAllAppenders方法的典型用法代碼示例。如果您正苦於以下問題:Java Logger.detachAndStopAllAppenders方法的具體用法?Java Logger.detachAndStopAllAppenders怎麽用?Java Logger.detachAndStopAllAppenders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ch.qos.logback.classic.Logger的用法示例。


在下文中一共展示了Logger.detachAndStopAllAppenders方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doInitializer

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
/**
 * Initializer logback
 * 
 * @param file
 * @param level
 * @param maxHistory
 */
private void doInitializer(String file, String level, int maxHistory) {
	LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
	rootLogger.detachAndStopAllAppenders();

	// appender
	RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
	fileAppender.setContext(loggerContext);
	fileAppender.setName("application");
	fileAppender.setFile(file);
	fileAppender.setAppend(true);

	// policy
	TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
	policy.setContext(loggerContext);
	policy.setMaxHistory(maxHistory);
	policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
	policy.setParent(fileAppender);
	policy.start();
	fileAppender.setRollingPolicy(policy);

	// encoder
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	encoder.setContext(loggerContext);
	encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
	encoder.start();
	fileAppender.setEncoder(encoder);
	
	fileAppender.start();

	rootLogger.addAppender(fileAppender);
	rootLogger.setLevel(Level.toLevel(level));
	rootLogger.setAdditive(false);
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:42,代碼來源:LogbackContainer.java

示例2: setCustomRootAppender

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
private static void setCustomRootAppender(Appender<ILoggingEvent> defaultAppender) {
  Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

  // by default it has an appender logging to stdout
  logger.detachAndStopAllAppenders();
  appender = new LogCallbackAppender(defaultAppender);
  appender.setName(CUSTOM_APPENDER_NAME);
  appender.start();

  logger.addAppender(appender);
}
 
開發者ID:instalint-org,項目名稱:instalint,代碼行數:12,代碼來源:SonarLintLogging.java


注:本文中的ch.qos.logback.classic.Logger.detachAndStopAllAppenders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。