本文整理匯總了Java中ch.qos.logback.classic.Logger.detachAppender方法的典型用法代碼示例。如果您正苦於以下問題:Java Logger.detachAppender方法的具體用法?Java Logger.detachAppender怎麽用?Java Logger.detachAppender使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ch.qos.logback.classic.Logger
的用法示例。
在下文中一共展示了Logger.detachAppender方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: apply
import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
@Override
public Statement apply(Statement base, FrameworkMethod method, Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
logAppender = new StubAppender();
Logger root = (Logger) LoggerFactory.getLogger(loggerName);
root.addAppender(logAppender);
try {
base.evaluate();
} finally {
root.detachAppender(logAppender);
}
}
};
}
示例2: configureInMemoryLogging
import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
private static void configureInMemoryLogging() {
org.slf4j.Logger rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
Logger logbackRootLogger = (Logger) rootLogger;
logbackRootLogger.setLevel(Level.INFO);
OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<>();
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("[%date] [%level] [%logger{10}] %msg%n");
ple.setContext(lc);
ple.start();
try {
ple.init(bos);
} catch (IOException e) {
}
appender.setContext(lc);
appender.setOutputStream(bos);
appender.setName("buffered");
appender.setEncoder(ple);
appender.start();
logbackRootLogger.detachAppender("console");
logbackRootLogger.addAppender(appender);
logbackRootLogger.setAdditive(true);
}
示例3: captureLogEvents
import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
public static <T> LogCapture<T> captureLogEvents(Supplier<T> codeBlock, String loggerName) {
StubAppender logAppender = new StubAppender();
Logger root = (Logger) LoggerFactory.getLogger(loggerName);
root.addAppender(logAppender);
try {
T result = codeBlock.get();
return new LogCapture<>(logAppender.events(), result);
} finally {
root.detachAppender(logAppender);
}
}
示例4: captureLogEventsAsync
import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
public static <T> LogCapture<T> captureLogEventsAsync(Supplier<T> codeBlock, Duration duration, ExpectedLoggingMessage expectedLoggingMessage) {
StubAppender logAppender = new StubAppender();
Logger root = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
root.addAppender(logAppender);
try {
T result = codeBlock.get();
awaitForLogMessage(duration, hasLoggedMessage(logAppender.events(), expectedLoggingMessage));
return new LogCapture<>(logAppender.events(), result);
} finally {
root.detachAppender(logAppender);
}
}
示例5: tearDown
import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.detachAppender(mockAppender);
}
示例6: detachDefaultConsoleAppender
import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
private void detachDefaultConsoleAppender() {
Logger rootLogger = getRootLogger();
Appender<ILoggingEvent> consoleAppender = rootLogger.getAppender("console");
rootLogger.detachAppender(consoleAppender);
}