- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的示例代码:
public class Logs {
private static Logs logHandler;
public static Logs handler() {
if (null == logHandler) {
logHandler = new Logs();
}
return logHandler;
}
public void logError(String message) {
Logger.getGlobal().log(Level.SEVERE, message);
}
}
我不太明白这两者之间的区别,因为它们提供完全相同的输出:
Logger.getGlobal.log(Level.SEVERE, message);
和:
Logger.getAnonymousLogger.log(Level.SEVERE, message);
有人可以告诉我它们的区别,以便我知道应该使用哪个吗?
提前谢谢您!
最佳答案
匿名记录器没有名称,这意味着您不能将记录器名称用作 formatter pattern 。匿名记录器不执行安全检查,这意味着任何代码都可以更改匿名记录器的设置。
全局记录器就是System.out
,可以说是日志记录API。它是一个命名记录器,如果代码尝试修改设置,它会执行安全检查。
文档建议您使用 named loggers如果可能的话。
来自GLOBAL_LOGGER_NAME文档:
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.
Create an anonymous Logger. The newly created Logger is not registered in the LogManager namespace. There will be no access checks on updates to the logger.
This factory method is primarily intended for use from applets. Because the resulting Logger is anonymous it can be kept private by the creating class. This removes the need for normal security checks, which in turn allows untrusted applet code to update the control state of the Logger. For example an applet can do a setLevel or an addHandler on an anonymous Logger.
Even although the new logger is anonymous, it is configured to have the root logger ("") as its parent. This means that by default it inherits its effective level and handlers from the root logger. Changing its parent via the setParent method will still require the security permission specified by that method.
此外,如果您要保留示例类,请确保通过创建静态最终字段来保留对全局记录器的强引用。
关于java - Logger.getGlobal() 和 Logger.getAnonymousLogger() 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46888178/
我正在尝试了解 Lua-C-API。为此,我编写了一个简单的回调函数,它尝试获取一个全局变量、打印其参数并推送两个返回值。我将要运行的 Lua 代码保存为 test.lua。阅读起来非常简单 var
一周前我用 LuaBridge 做了第一次小测试,它成功地从脚本中获取了一个 int。 现在我删除了这段代码并尝试在我的游戏引擎中包含 Lua 脚本,但它不再有效。我试着用这个回到基本代码: #inc
本文整理了Java中gov.nasa.worldwind.WorldWindow.getGlobe()方法的一些代码示例,展示了WorldWindow.getGlobe()的具体用法。这些代码示例主要
这是我的示例代码: public class Logs { private static Logs logHandler; public static Logs handler() {
我一直在摆弄 Electron 的远程模块。在我的主进程中,我创建了这个变量: global.storage = {}; 我的渲染器进程是用一个名为 startup.html 的文件初始化的。 win
我是一名优秀的程序员,十分优秀!