将日志记录添加到实用程序包

发布于 2024-12-08 21:52:38 字数 216 浏览 0 评论 0原文

我正在创建一个 java 开源实用程序包,我想知道是否可以将日志记录(如 log4j)包含到该包中。

困境是,如果我将 log4j 包含到我的包中,我将在哪里输出日志文件,我不希望日志文件位于用户的错误位置,但我仍然想创建用于调试的日志。

还有一个问题是用户希望将我的日志集成到项目本身中。 他怎样才能做到这一点?

您建议这样做的最佳方法是什么?

谢谢。

I'm creating a java open source utility package and I would like to know if it is ok to include logging (like log4j) into that package.

The dilemma is if I include log4j into my package, where will i output the log file, I wouldn't want the log file to be at a wrong place for the user, but i would still want to create logs for debugging.

As well there is the issue of the user wanting to integrate my logs into the project itself.
and how will he be able to do that.

What would you recommend is the best way of doing this?

Thanks.

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

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

发布评论

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

评论(1

冷弦 2024-12-15 21:52:38

我认为正常的方法是不将 Log4j Jar 包含在包中,并让库用户决定使用哪个版本的 Log4j。

此外,您不必担心在哪里输出日志文件,因为用户将有自己的 log4j.properties 或 log4j.xml 配置。

库用户还可以决定使用库中的日志记录级别或是否禁止它。例如,对于 Amazon AWS 库,我可以知道我只需要警告消息,否则输出将过于冗长。在这种情况下,我添加到我的 log4j.properties 中:

log4j.logger.com.amazonaws=WARN

话虽如此,我还要提醒您 log4j 的现代替代品是 SL4J

I think the normal way to do it, is not include the Log4j Jar in the package and let the library user to decide which version of Log4j to use.

Also you don't have to worry about where to output the log file, since the user will have its own log4j.properties or log4j.xml configuration.

The library user can also decide which level of logging to use from your library or whether to suppress it. For instance with Amazon AWS libraries, I can tell that I only want warning messages or the output will be too verbose. In that case I add to my log4j.properties:

log4j.logger.com.amazonaws=WARN

Said that, I'd also remind you that a modern alternative to log4j is SL4J.

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