为什么 org.jboss.logging.Logger 不推荐使用 Logger.isInfoEnabled?

发布于 2024-10-01 04:53:32 字数 493 浏览 0 评论 0原文

我已经有几年没有使用 Log4J 了。我现在正在 JBoss 5 下使用 org.jboss.logging 包开发一个应用程序。当我以前这样做时,将 logger.info() 消息包含在日志记录级别检查中是一种常见的技术。如果信息消息无论如何都会被丢弃,那么这就避免了创建信息消息的相对昂贵的操作。下面是一个示例:

  if (logger.isInfoEnabled()) {
        logger.info("AddRedemption response: \"" 
                    + redemptionResponse.getResponseString() + "\"");
    }

但现在我发现我值得信赖的 IDE 警告我 isInfoEnabled 已被弃用。这直接引出了我的两个问题:

  1. 为什么它被弃用?
  2. 我应该用什么来代替?

预先感谢您的帮助。

-标记

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:

  1. Why is it deprecated?
  2. What should I use instead?

Thanks in advance for your help.

-mark

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的心境我的脸 2024-10-08 04:53:32

正如评论中提到的,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文