你觉得 java.util.logging 足够了吗? [英] Do you find java.util.logging sufficient?

查看:30
本文介绍了你觉得 java.util.logging 足够了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据标题,您是否发现默认的 Java 日志框架足以满足您的需求?

Per the title, do you find the default Java logging framework sufficient for your needs?

您是否使用替代的日志记录服务,例如 log4j 或其他?如果是这样,为什么?我想听听您对不同类型项目的日志记录要求的任何建议,以及何时集成框架实际上是必要和/或有用的.

Do you use alternative logging services such as log4j or others? If so, why? I'd like to hear any advice you have regarding logging requirements in different types of projects, and when integrating frameworks is actually necessary and/or useful.

推荐答案

使用第三方库记录依赖关系

在大多数情况下,Java JDK 日志记录本身并不够.但是,如果您有一个使用多个开源第三方库的大型项目,您会很快发现其中许多具有不同的日志记录依赖项.

Logging Dependencies with Third Party Libraries

Java JDK logging in most cases is not insufficient by itself. However, if you have a large project that uses multiple open-source third party libraries, you will quickly discover that many of them have disparate logging dependencies.

正是在这些情况下,从日志实现中抽象出日志 API 的需求变得很重要.我推荐使用 slf4jlogback(使用 slf4j API)作为您的 API,如果您想坚持使用 Java JDK 日志记录,您仍然可以!Slf4j 可以毫无问题地输出到许多不同的记录器实现.

It is in these cases where the need to abstract your logging API from your logging implementation become important. I recommend using slf4j or logback (uses the slf4j API) as your API and if you want to stick with Java JDK logging, you still can! Slf4j can output to many different logger implementations with no problems.

在最近的一个项目中发生了它有用的一个具体例子:我们需要使用需要 log4j 的第三方库,但我们不想并排运行两个日志框架,所以我们使用了 slf4j log4j api 包装器库问题就解决了.

A concrete example of its usefulness happened during a recent project: we needed to use third-party libs that needed log4j, but we did not want to run two logging frameworks side by side, so we used the slf4j log4j api wrapper libs and the problem was solved.

总而言之,Java JDK 日志记录很好,但从长远来看,我的第三方库中使用的标准化 API 将节省您的时间.试想一下重构每个日志语句!

In summary, Java JDK logging is fine, but a standardized API that is used in my third party libraries will save you time in the long run. Just try to imagine refactoring every logging statement!

这篇关于你觉得 java.util.logging 足够了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆