本文整理匯總了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);
}
示例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);
}