Logger.getGlobal()
不是所有七月伐木者的根源。所有七月伐木者的根源是
Logger.getLogger("")
pin those loggers
因此,在垃圾收集时不会恢复设置。
您需要确保日志记录并发布到
parent handlers
private static final java.util.logging.Logger[] pin;
static {
//Pin first.
pin = new java.util.logging.Logger[] {
java.util.logging.Logger.getLogger(""),
java.util.logging.Logger.getLogger("3rd.party.package") };
//Setup SLF4J
LogManager.getLogManager().reset();
SLF4JBridgeHandler.removeHandlersForRootLogger();
//SLF4JBridgeHandler.install();
java.util.logging.Logger.getLogger("").addHandler(new SLF4JBridgeHandler());
//Change JUL levels.
for (java.util.logging.Logger l : pin) {
l.setLevel(Level.FINEST);
}
}
您还应该尝试:
public class MyTestActivator implements BundleActivator {
static {
//Pin first.
pin = new java.util.logging.Logger[] {
java.util.logging.Logger.getLogger(""),
java.util.logging.Logger.getLogger("3rd.party.package") };
//Change JUL levels.
for (java.util.logging.Logger l : pin) {
l.setLevel(Level.FINEST);
}
}
@Override
public void start(final BundleContext bundleContext) throws Exception {
try {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
try {
context.reset();
configurator.doConfigure(getClass().getResourceAsStream("/logback.xml"));
//Setup SLF4J
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
} catch (JoranException e) {
throw new IOException(e.getMessage(), e);
}
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
} catch (final IOException e) {
e.printStackTrace();
}
}
}
将根记录器的中的logback级别设置为
debug
trace
。与设置logback控制台附加程序的级别相同。
唯一的缺点是,我可能必须捕捉每个记录器并执行此操作。
Iteration over the installed the loggers
可以执行,但记录器树将随时间变化。
唯一的缺点是,我可能必须捕捉每个记录器并执行此操作。当我查看调试器时,我注意到它们都没有父对象(为null)
或者,您可以添加一个
new SLF4JBridgeHandler()
对于每个想要监视的记录器,但这不如监视根记录器好。