我想知道如何以编程方式关闭java日志记录 - 没有属性文件,没有命令行参数等。
我试过了:
final Properties logProperties = new Properties();
logProperties.put("handlers", "java.util.logging.MemoryHandler");
logProperties.put(".level", "SEVERE");
logProperties.put("java.util.logging.ConsoleHandler.level", "SEVERE");
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
logProperties.store(bytes, applicationName);
new String(bytes.toByteArray());
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(bytes.toByteArray()));
但是无论我做什么,第三方图书馆(Flying Saucer)都会继续记录所有邮件。
在制作中这并不重要,但在我的IDE中,在整个节目中获取这些控制台消息真的很烦人。 (在未来,我将重定向到另一个日志框架......)
答案 0 :(得分:3)
System.setProperty("show-config", "OFF");
System.setProperty("xr.util-logging.plumbing.layout.level", "OFF");
System.setProperty("xr.util-logging.plumbing.config.level", "OFF");
System.setProperty("xr.util-logging.plumbing.load.xml-entities.level",
"OFF");
System.setProperty("xr.util-logging.plumbing.init.level", "OFF");
System.setProperty(
"xr.util-logging.java.util.logging.ConsoleHandler.level", "OFF");
System.setProperty("xr.util-logging.plumbing.exception.level", "OFF");
System.setProperty("xr.util-logging.plumbing.match.level", "OFF");
System.setProperty("xr.util-logging..level", "OFF");
System.setProperty("xr.util-logging.plumbing.cascade.level", "OFF");
System.setProperty("xr.util-logging.plumbing.load.level", "OFF");
System.setProperty("xr.util-logging.plumbing.css-parse.level", "OFF");
System.setProperty("xr.util-logging.plumbing.render.level", "OFF");
System.setProperty("xr.util-logging.plumbing.level", "OFF");
System.setProperty("xr.util-logging.plumbing.general.level", "OFF");
( per https://xhtmlrenderer.dev.java.net/servlets/ReadMsg?list=users&msgNo=142 )
答案 1 :(得分:0)
类似于Yuval的回答:
System.setProperty("xr.util-logging.loggingEnabled", "false")
这适用于xr(爱德华),但我真的在寻找能够关闭所有日志记录的神奇之物(虽然这对我来说很好......)