本文整理汇总了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);
}