java 日志记录 API,禁用日志记录到标准输出
使用标准的java日志记录API(导入java.util.logging.Logger),构建后:
Logger l = Logger.getLogger("mylogger");
我已经能够记录一些东西了。由于它没有 FileHandler,因此它不会向磁盘写入任何内容。
l.severe("test with no handler");
它将(部分,不是全部)日志消息写入输出。 如何禁用此功能? 提前致谢 阿戈斯蒂诺
Using the standard java logging API (import java.util.logging.Logger), after the construction:
Logger l = Logger.getLogger("mylogger");
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");
It writes (some, not all) the log messages to output.
How can I disable this feature?
thanks in advance
Agostino
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不知道 java util 日志记录的默认配置,就会出现问题。
建筑事实:
0)每个记录器,无论其名称是什么,都将根记录器作为父记录器。
默认事实:
1)logger属性useParentHandlers默认为true
2)根记录器默认有一个ConsoleHandler
所以。默认情况下,新记录器也会将其日志记录发送到其父记录器(点 1),即根记录器(点 0),默认情况下,将它们记录到控制台(点 2)。
删除控制台日志记录很简单:
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
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:
Java 中的标准 Logger 具有层次结构,子 Logger 默认继承其父级的 Handler。尝试这样做来禁止使用父处理程序:
Standard Loggers in Java are in a hierarchical structure and child Loggers by default inherit the Handlers of their parents. Try this to suppress parent Handlers from being used: