Search code examples
javaopen-sourcelog4jslf4japache-commons-logging

Choice of logging framework for open source java project


Recently I published my open source java game server code to github and faced the following dilemma "which logging should I use".I want my library to have most "ease of use" for end developer. I hope to create a pseudo-wiki out of this question so that others facing same issue can have a single point of reference.

1) If your open source project is a simple java library, what are the options available for logging.
a. Use your own logging logic
b. Print to console,err
c. Use a library like log4j, slf4j etc
2) What are the best practices? Which one of the above is the general preference for open source libraries?
3) For some of the famous logging frameworks out there, like log4j, slf4j, commons-logging etc what are known issues that need to be considered while selecting it as your logging library.
4) Will my choice of logging framework impact another library which uses mine? Is there possibility of incompatibilities if I use a specific library?

If you have some additional comments like "log only to console", "dont use logging" etc then please justify.


Solution

  • Never write directly to console ;) If someone uses your library he might want to have console for himself, not for your logs.

    slf4j (and commons-logging) is not a logging framework. It's an abstraction layer which lets you program vs one interface and use the implementation of your (or the end user of your library) choice, be it log4j, java logging or whatever. I'd go for that as it leaves the choice of implementation up to the user.