是否有专为 Java 5 或更高版本设计的 log4j 或 commons 日志扩展或其他日志框架?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Log5j 正是您所需要的。
Log5j is exacly what you need.
Java 的简单日志外观 (SLF4J)
示例:
生成“Hello world!” 但仅当信息级别启用时。
Simple Logging Facade for Java (SLF4J)
Example:
produces "Hello world!" but only if info level is enabled.
为此编写您自己的包装方法很容易。
It is easy enough to write your own wrapper methods for that.