Sometimes when I see my logging code I wonder if I am doing it right. There might be no definitive answer to that, but I have the following concerns:
Library Classes
I have several library classes which might log some INFO
messages. Fatal Errors are reported as exceptions. Currently I have a static logger instance in my classes with the class name as the logging name. (Log4j's: Logger.getLogger(MyClass.class)
)
Is this the right way? Maybe the user of this library class doesn't want any messages from my implementation or wants to redirect them to an application specific log. Should I allow the user to set a logger from the "outside world"? How do you handle such cases?
General logs
In some applications my classes might want to write a log message to a specific log not identified by the class' name. (I.e.: HTTP Request log
) What is the best way to do such a thing? A lookup service comes to mind...