Instead of specifying the class name on each class:
log = Logger.getLogger(Foo.class);
log = Logger.getLogger(Bar.class);
log = Logger.getLogger(Test.class);
Will it be OK to use :
log = Logger.getLogger(this.getClass());
What will be the implications?
Try this way to look up a generic class...
The best part is you can use this method statically.
Sure that seems fine.
Be aware that one implication is that if you may have trouble using the log from a static context - It may not be initialized or it may not be visible
Using log factory from Apache commons:
Don't have to do anything else. Not sure LogFactory was available at time of question post. If you don't want to use LogFactory you could also simply use private final with the getClass().
No reason to create subclasses unless you want a heirarchy of your logging which could also be done with manipulation of the log configuration file (log4j.xml if that's what you are using). You just can't use this.getClass() when the logger is defined as static. Without static or private final you leave the logger open to dangerous possible changes which you don't want.
There is no implications as I know. As per Matt comment, I guess, thats the right behaviour which everyone wants it.
If you create a subclass, the log messages will get logged to the subclass's logger.
.
.
In the above example, "Doing something" will get logged to the pkgtwo.SubType logger instead of pkgone.SuperType logger, which may or may not be what you want.
+1 for sublass instances that call a super method, the logger will be the sub class.
Also if you are applying this as a logging template for your classes, if your class is abstract - your this.getClass will fail as you do not have an instance of this class.