[slf4j-dev] [Bug 305] New: Add default logger method
bugzilla-daemon at qos.ch
bugzilla-daemon at qos.ch
Fri Jul 5 23:42:20 CEST 2013
http://bugzilla.slf4j.org/show_bug.cgi?id=305
Priority: P5
Bug ID: 305
Assignee: slf4j-dev at qos.ch
Summary: Add default logger method
Severity: enhancement
Classification: Unclassified
OS: All
Reporter: ggerard at gmail.com
Hardware: All
Status: NEW
Version: 1.7.x
Component: Core API
Product: SLF4J
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());
}
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-dev/attachments/20130705/c8bf215e/attachment.html>
More information about the slf4j-dev
mailing list