开发者

add logging to a utility package

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 t开发者_高级运维he 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜