将日志记录添加到实用程序包
我正在创建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为正常的方法是不将 Log4j Jar 包含在包中,并让库用户决定使用哪个版本的 Log4j。
此外,您不必担心在哪里输出日志文件,因为用户将有自己的 log4j.properties 或 log4j.xml 配置。
库用户还可以决定使用库中的日志记录级别或是否禁止它。例如,对于 Amazon AWS 库,我可以知道我只需要警告消息,否则输出将过于冗长。在这种情况下,我添加到我的 log4j.properties 中:
话虽如此,我还要提醒您 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:
Said that, I'd also remind you that a modern alternative to log4j is SL4J.