是否有专为 Java 5 或更高版本设计的 log4j 或 commons 日志扩展或其他日志框架?

发布于 2024-07-14 00:04:17 字数 455 浏览 5 评论 0原文

Java 5 引入了许多可以使日志记录语句不再混乱的功能,例如可变数量的参数和 printf。 这可以减轻记录某些内容时发生的所有消息构建代码以及周围的 if

例如,我不想写:

if (log.isDebugEnabled()
{
    log.debug("User id: "+uid+", Request id:"
    + rid +", Client IP: "+ip+" blah blah blah");
}

我想写:

log.debug("User id: %s, Request id: %s, Client IP: %s blah blah blah",
uid, rid, ip);

或类似的东西。

您知道可以帮助解决此问题的日志记录框架或日志记录框架的扩展吗?

Java 5 has introduced many features that can be make logging statements less cluttering, such as variable number of arguments and printf. That can alleviate all the message building code that happens when something is logged, as well as the surrounding if.

For example, instead of writing:

if (log.isDebugEnabled()
{
    log.debug("User id: "+uid+", Request id:"
    + rid +", Client IP: "+ip+" blah blah blah");
}

I would like to write:

log.debug("User id: %s, Request id: %s, Client IP: %s blah blah blah",
uid, rid, ip);

or something like that.

Do you know a logging framework or an extension to a logging framework that can help with that?

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

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

发布评论

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

评论(3

偏爱你一生 2024-07-21 00:04:17

Log5j 正是您所需要的。

Log5j is exacly what you need.

素手挽清风 2024-07-21 00:04:17

Java 的简单日志外观 (SLF4J)

Java 的简单日志外观或
(SLF4J)旨在充当
各种日志 API 的简单外观
允许最终用户插入
期望的实施
部署时间。 SLF4J 还支持
桥接遗留 API 以及
源代码迁移工具。

SLF4J API 提供了先进的
各种日志记录的抽象
系统,包括 JDK 1.4 日志记录,
log4j 和 logback。 特点包括
参数化日志记录和 MDC 支持。

示例:

logger.info("{} {}!", "Hello", "world");

生成“Hello world!” 但仅当信息级别启用时。

Simple Logging Facade for Java (SLF4J)

The Simple Logging Facade for Java or
(SLF4J) is intended to serve as a
simple facade for various logging APIs
allowing to the end-user to plug in
the desired implementation at
deployment time. SLF4J also supports a
bridging legacy APIs as well as a
source code migration tool.

SLF4J API offers an advanced
abstraction of various logging
systems, including JDK 1.4 logging,
log4j and logback. Features include
parameterized logging and MDC support.

Example:

logger.info("{} {}!", "Hello", "world");

produces "Hello world!" but only if info level is enabled.

篱下浅笙歌 2024-07-21 00:04:17

为此编写您自己的包装方法很容易。

It is easy enough to write your own wrapper methods for that.

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