本文整理了Java中ch.qos.logback.classic.Logger.detachAndStopAllAppenders()
方法的一些代码示例,展示了Logger.detachAndStopAllAppenders()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger.detachAndStopAllAppenders()
方法的具体详情如下:
包路径:ch.qos.logback.classic.Logger
类名称:Logger
方法名:detachAndStopAllAppenders
[英]Remove all previously added appenders from this logger instance.
This is useful when re-reading configuration information.
[中]从此记录器实例中删除以前添加的所有附加程序。
这在重新读取配置信息时非常有用。
代码示例来源:origin: jmxtrans/jmxtrans
@Override
public void close() {
for(Logger logger: this.loggers.values()) {
logger.detachAndStopAllAppenders();
}
this.loggers.clear();
}
代码示例来源:origin: jmxtrans/jmxtrans
@Override
public void close() {
for(Logger logger: this.loggers.values()) {
logger.detachAndStopAllAppenders();
}
this.loggers.clear();
}
代码示例来源:origin: ch.qos.logback/logback-classic
void recursiveReset() {
detachAndStopAllAppenders();
localLevelReset();
additive = true;
if (childrenList == null) {
return;
}
for (Logger childLogger : childrenList) {
childLogger.recursiveReset();
}
}
代码示例来源:origin: alibaba/nacos
@Override
public void activateAppender(String productName, String file, String encoding) {
ch.qos.logback.core.Appender appender = getLogbackDailyRollingFileAppender(productName, file, encoding);
logger.detachAndStopAllAppenders();
logger.addAppender(appender);
setProductName(productName);
}
代码示例来源:origin: alibaba/nacos
@Override
public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size) {
ch.qos.logback.core.Appender appender = getLogbackDailyAndSizeRollingFileAppender(productName, file, encoding,
size);
logger.detachAndStopAllAppenders();
logger.addAppender(appender);
setProductName(productName);
}
代码示例来源:origin: alibaba/nacos
@Override
public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size,
String datePattern) {
ch.qos.logback.core.Appender appender = getLogbackDailyAndSizeRollingFileAppender(productName, file, encoding,
size, datePattern, -1);
logger.detachAndStopAllAppenders();
logger.addAppender(appender);
setProductName(productName);
}
代码示例来源:origin: alibaba/nacos
@Override
public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size,
String datePattern, int maxBackupIndex) {
ch.qos.logback.core.Appender appender = getLogbackDailyAndSizeRollingFileAppender(productName, file, encoding,
size, datePattern,
maxBackupIndex);
logger.detachAndStopAllAppenders();
logger.addAppender(appender);
setProductName(productName);
}
代码示例来源:origin: alibaba/nacos
@Override
public void activateAppenderWithSizeRolling(String productName, String file, String encoding, String size,
int maxBackupIndex) {
ch.qos.logback.core.Appender appender = getSizeRollingAppender(productName, file, encoding, size,
maxBackupIndex);
logger.detachAndStopAllAppenders();
logger.addAppender(appender);
setProductName(productName);
}
代码示例来源:origin: alibaba/nacos
@Override
public void activateAppender(Logger logger) {
if (!(logger.getDelegate() instanceof ch.qos.logback.classic.Logger)) {
throw new IllegalArgumentException(
"logger must be ch.qos.logback.classic.Logger, but it's " + logger.getDelegate().getClass());
}
this.logger.detachAndStopAllAppenders();
Iterator<ch.qos.logback.core.Appender<ILoggingEvent>> iter = ((ch.qos.logback.classic.Logger)logger
.getDelegate()).iteratorForAppenders();
while (iter.hasNext()) {
ch.qos.logback.core.Appender<ILoggingEvent> appender = iter.next();
this.logger.addAppender(appender);
}
}
代码示例来源:origin: dropwizard/dropwizard
/**
* This method is designed to be used by unit tests only.
*/
void clear() {
// This is volatile, read once for performance.
final String name = loggerName;
if (name != null) {
CHANGE_LOGGER_CONTEXT_LOCK.lock();
try {
loggerContext.stop();
final Logger logger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
logger.detachAndStopAllAppenders();
// Additional cleanup/reset for this name
configureLoggers(name);
} finally {
CHANGE_LOGGER_CONTEXT_LOCK.unlock();
}
StatusPrinter.setPrintStream(System.out);
}
}
代码示例来源:origin: SonarSource/sonarqube
private static void setCustomRootAppender(LoggingConfiguration conf) {
Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
String level = StringUtils.defaultIfBlank(conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), LoggingConfiguration.LEVEL_ROOT_DEFAULT);
if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) {
logger.detachAndStopAllAppenders();
logger.addAppender(createAppender(conf.getLogOutput()));
}
logger.setLevel(Level.toLevel(level));
}
代码示例来源:origin: dropwizard/dropwizard
@Override
public void reset() {
CHANGE_LOGGER_CONTEXT_LOCK.lock();
try {
// Flush all the loggers and reinstate only the console logger as a
// sane default.
loggerContext.stop();
final Logger logger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
logger.detachAndStopAllAppenders();
final DropwizardLayout formatter = new DropwizardLayout(loggerContext, TimeZone.getDefault());
formatter.start();
final LayoutWrappingEncoder<ILoggingEvent> layoutEncoder = new LayoutWrappingEncoder<>();
layoutEncoder.setLayout(formatter);
final ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.addFilter(new ThresholdLevelFilterFactory().build(Level.INFO));
consoleAppender.setEncoder(layoutEncoder);
consoleAppender.setContext(loggerContext);
consoleAppender.start();
logger.addAppender(consoleAppender);
loggerContext.start();
} finally {
CHANGE_LOGGER_CONTEXT_LOCK.unlock();
}
}
代码示例来源:origin: dropwizard/dropwizard
root.detachAndStopAllAppenders();
代码示例来源:origin: apache/incubator-dubbo
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.detachAndStopAllAppenders();
代码示例来源:origin: apache/incubator-dubbo
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.detachAndStopAllAppenders();
代码示例来源:origin: alibaba/nacos
@Override
public void activateConsoleAppender(String target, String encoding) {
ch.qos.logback.core.ConsoleAppender appender = new ch.qos.logback.core.ConsoleAppender();
appender.setContext(LogbackLoggerContextUtil.getLoggerContext());
appender.setTarget(target);
PatternLayout layout = new PatternLayout();
layout.setPattern(LoggerHelper.getPattern());
layout.setContext(LogbackLoggerContextUtil.getLoggerContext());
layout.start();
appender.setLayout(layout);
appender.start();
logger.detachAndStopAllAppenders();
logger.addAppender(appender);
}
代码示例来源:origin: HubSpot/Singularity
public Logger prepareRootLogger(LoggerContext context) {
Logger rootLogger = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
rootLogger.detachAndStopAllAppenders();
return rootLogger;
}
代码示例来源:origin: camunda/camunda-bpm-platform
void recursiveReset() {
detachAndStopAllAppenders();
localLevelReset();
additive = true;
if (childrenList == null) {
return;
}
for (Logger childLogger : childrenList) {
childLogger.recursiveReset();
}
}
代码示例来源:origin: HubSpot/Singularity
public void stopTaskLogger(String taskId, Logger logger) {
LOG.info("Stopping task logger for {}", taskId);
try {
logger.info("Task finished, stopping logger");
logger.detachAndStopAllAppenders();
logger.getLoggerContext().stop();
} catch (Throwable t) {
LOG.error("While closing task logger for {}", taskId, t);
}
}
代码示例来源:origin: HubSpot/Singularity
public Logger buildTaskLogger(String taskId, String executorId, String executorPid, String taskLogFile) {
LOG.info("Building a task logger for {} pointing to {}", taskId, taskLogFile);
LoggerContext context = new LoggerContext();
context.setName(executorPid);
baseLogging.prepareRootLogger(context);
String loggerId = taskId;
try {
SingularityTaskId singularityTaskId = SingularityTaskId.valueOf(taskId);
loggerId = String.format("%s.%s.%s.%s.%s", singularityTaskId.getRequestId(), singularityTaskId.getDeployId(), singularityTaskId.getStartedAt(),
singularityTaskId.getInstanceNo(), executorId);
} catch (InvalidSingularityTaskIdException e) {
LOG.info("Handling non-SingularityTaskId %s", taskId);
}
Logger taskLogger = context.getLogger(loggerId);
taskLogger.detachAndStopAllAppenders();
if (baseLogging.getRootLogPath().isPresent()) {
taskLogger.addAppender(baseLogging.buildFileAppender(context, baseLogging.getRootLogPath().get()));
}
taskLogger.addAppender(baseLogging.buildFileAppender(context, taskLogFile));
context.start();
return taskLogger;
}
内容来源于网络,如有侵权,请联系作者删除!