为什么 org.jboss.logging.Logger 不推荐使用 Logger.isInfoEnabled?
我已经有几年没有使用 Log4J 了。我现在正在 JBoss 5 下使用 org.jboss.logging 包开发一个应用程序。当我以前这样做时,将 logger.info() 消息包含在日志记录级别检查中是一种常见的技术。如果信息消息无论如何都会被丢弃,那么这就避免了创建信息消息的相对昂贵的操作。下面是一个示例:
if (logger.isInfoEnabled()) {
logger.info("AddRedemption response: \""
+ redemptionResponse.getResponseString() + "\"");
}
但现在我发现我值得信赖的 IDE 警告我 isInfoEnabled 已被弃用。这直接引出了我的两个问题:
- 为什么它被弃用?
- 我应该用什么来代替?
预先感谢您的帮助。
-标记
I have been away from using Log4J for a few years. I'm now working on an application under JBoss 5, using the org.jboss.logging package. Back when I used to do this, it was a common technique to enclose the logger.info() messages inside of a check of the logging level. This avoided relatively expensive operation of creating the info message if it was just going to be thrown out anyway. Here is an example:
if (logger.isInfoEnabled()) {
logger.info("AddRedemption response: \""
+ redemptionResponse.getResponseString() + "\"");
}
But now I'm finding that my trusty IDE is warning me that isInfoEnabled is deprecated. This leads directly to my two questions:
- Why is it deprecated?
- What should I use instead?
Thanks in advance for your help.
-mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中提到的,JBoss Logger INFO 日志级别用于记录少量信息。没有提到的是,INFO 日志记录级别始终打印在控制台(屏幕)上,因此没有捕获 INFO 级别的日志文件。弃用它是有道理的,因为开发人员不需要它。
Dimitris Andreadi 有一个有趣的博客关于 JBoss 日志记录的某些日志记录级别的弃用。
As mentioned on the comment, JBoss Logger INFO logging level is used to log low volume information. What it's not mentioned is that the INFO logging level always printed on the console(screen) so there was no logged file that captured the INFO level. It made sense for deprecating it as developers didn't need it.
There's an interesting blog by Dimitris Andreadi about certain logging level deprecation of JBoss logging.