我想知道如何以编程方式关闭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()));
但是无论我做什么,第三方库(飞碟)都会继续记录其所有消息。
在生产中并没有太大关系,但是在我的IDE中,在整个演出中获得这些控制台消息确实很烦人。 (将来,我将重定向到另一个日志记录框架...)
最佳答案
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");
(每个https://xhtmlrenderer.dev.java.net/servlets/ReadMsg?list=users&msgNo=142)