java logging API,禁用日志记录到标准输出 [英] java logging API, disable logging to standard output
问题描述
使用标准java日志API(导入java.util.logging.Logger),构造完成后:
Using the standard java logging API (import java.util.logging.Logger), after the construction:
Logger l = Logger.getLogger("mylogger");
我已经能够记录一些东西了。由于它没有FileHandler,因此它不会向磁盘写入任何内容。
I am already able to log something. Since it has not a FileHandler, it doesn't write anything to disk.
l.severe("test with no handler");
它将(有些,而不是全部)日志消息写入输出。
如何禁用此功能?
提前感谢
Agostino
It writes (some, not all) the log messages to output. How can I disable this feature? thanks in advance Agostino
推荐答案
如果您不知道默认配置,则会出现问题java util logging。
建筑事实:
0)每个记录器的名称都是根记录器作为父记录器。
默认值:
1)logger属性useParentHandlers默认为true
2)根记录器默认有一个ConsoleHandler
The question arises if you don't know the default configuration of java util logging. Architectural fact: 0)Every logger whatever its name is has the root logger as parent. Default facts: 1) the logger property useParentHandlers is true by default 2) the root logger has a ConsoleHandler by default
所以。默认情况下,新的记录器也将其日志记录发送到他的父记录(点1),即根记录器(点0),默认情况下,将它们记录到控制台(点2)。
So. A new logger, by default sends its log records also to his parent(point 1) that is the root logger(point 0) wich, by default, logs them to console(point 2).
删除控制台日志记录很简单:
Remove console logging is easy as:
Logger l0 = Logger.getLogger("");
l0.removeHandler(l0.getHandlers()[0]);
这篇关于java logging API,禁用日志记录到标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!