06 March 2003 - java_dev (original) (raw)
If you've used any logging toolkit (Log4J, Apache LogKit, the one that ended up in JDK 1.4, the one I wrote (!), etc. etc.) you will quite probably have created loggers with the class name as a parameter to the constructor, something like this:
private static Logger log = new Logger ( "my.class.name" ); // or... private static Logger log = new Logger ( ThisClass.class.getName() );
The problem is that you have to hard code the class name in one way or another. If (like me) you tend to copy that kind of code around, then sooner or later the logger will get initialised with the wrong class name.
I asked about this some time ago, and renniekins had a nice suggestion. However, it relies on JDK 1.4. Ever since I've used Java, work projects have been a version behind, so I can't use it.
Today I was looking at Cocoon logging API docs, and they have another solution that should work in any JDK.