在java.util.logging中,全局记录器是做什么用的? [英] In java.util.logging, what is the global logger for?

查看:61
本文介绍了在java.util.logging中,全局记录器是做什么用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.util.logging 日志记录框架,其中有一个特殊的 c1> 实例命名为"global",但是我找不到有关其预期用途的任何文档. Logger.getGlobal() 只是说

In the java.util.logging logging framework there's a special Logger instance named "global", but I can't find any documentation of what its intended use is. The documentation for Logger.getGlobal() just says

返回名称为Logger.GLOBAL_LOGGER_NAME的全局记录器对象.

Return global logger object with the name Logger.GLOBAL_LOGGER_NAME.

Logger.GLOBAL_LOGGER_NAME 仅记录为

Logger.GLOBAL_LOGGER_NAME, in turn, is documented only as

GLOBAL_LOGGER_NAME是全局记录器的名称.

GLOBAL_LOGGER_NAME is a name for the global logger.

我进行了广泛的搜索,没有找到更多有用的文档.

My fairly extensive searches didn't turn up any more useful documentation.

全局记录器打算用于什么?那是我错过的地方吗?

What is the global logger intended to be used for? Is that documented somewhere that I missed?

推荐答案

为方便开发人员而提供了全局" Logger对象 谁正在随意使用Logging程序包.谁是开发人员 认真使用日志记录包(例如在产品中) 应该在适当的情况下创建并使用自己的Logger对象 名称,以便可以在适当的每个Logger上控制日志记录 粒度.开发人员还需要牢记自己的 记录器对象,以防止它们被垃圾收集.

The "global" Logger object is provided as a convenience to developers who are making casual use of the Logging package. Developers who are making serious use of the logging package (for example in products) should create and use their own Logger objects, with appropriate names, so that logging can be controlled on a suitable per-Logger granularity. Developers also need to keep a strong reference to their Logger objects to prevent them from being garbage collected.

此处 (不要看这个字段已经过时的事实,我只是想为您指出一个有效的解释).

From here (don't look at the fact that the field is deprecated, I just wanted to point you to a valid explanation).

通常,在启用应用程序日志记录时,通常按Java包或类定义更精细的记录器.

Normally, when enabling logging in an application, you define more granular loggers, usually per Java packages or classes.

如果您不想这样做,则可以使用此全局记录器,该处理程序将处理所有记录语句,无论它们包含在哪个库,程序包或类中.

If you do not want to do that, you can use this global logger, which will handle all logging statements, no matter the library, package or class they are contained in.

这篇关于在java.util.logging中,全局记录器是做什么用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆