I’m writing a library that gathers various functions that I’ll be using in different applications. I want it to generate log statements visible for the user of the library, i.e., if I’m building an application and I’m using the library, I want the library to generate log statements visible to me. How do I do that? Since the log file will be configured by the developer of the application, how will my library know how to log?
I’m writing a library that gathers various functions that I’ll be using in different
Share
If you are developing a library the others will include in their application you should use a logging facade. Otherwise you force the users of your library to configure and include the logging framework you have choosen in addition to the framework they chose for their application.
For instance if you use log4j but the developer using your library uses logback he will have to include a log4j configuration file and the log4j jar (or take other measures) to make your library happy.
Logging Facades solve this problem (from Apache Commons Logging):
Or the reasoning from SLF4J:
Candidates for logging facades are:
Personally I would recommend SLF4J (with Logback).