Details
-
Improvement
-
Resolution: Unresolved
-
None
-
1.7.x
-
None
-
Operating System: All
Platform: All
-
enhancement
-
P5
-
305
Description
The typical way of adding logging to a class involves a reference to the class itself:
private static final Logger kLogger = LoggerFactory.getLogger(MyClass.class);
Not all tooling catches renames and whatnot – I've had several occasions where the old class reference inadvertently came along for the ride and made for misleading logs.
I started putting this into a little utility class in my projects to prevent this and I think it would be a good addition to LoggerFactory. While the stacktrace calls might not be the cheapest, it's only hit during class initialization.
public static Logger getDefaultClassLogger()
{ return LoggerFactory.getLogger(Thread.currentThread().getStackTrace()[2].getClassName()); }