<html>
<head>
<base href="http://bugzilla.slf4j.org/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Priority</th>
<td>P5
</td>
</tr>
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Add default logger method"
href="http://bugzilla.slf4j.org/show_bug.cgi?id=305">305</a>
</td>
</tr>
<tr>
<th>Assignee</th>
<td>slf4j-dev@qos.ch
</td>
</tr>
<tr>
<th>Summary</th>
<td>Add default logger method
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ggerard@gmail.com
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Version</th>
<td>1.7.x
</td>
</tr>
<tr>
<th>Component</th>
<td>Core API
</td>
</tr>
<tr>
<th>Product</th>
<td>SLF4J
</td>
</tr></table>
<p>
<div>
<pre>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());
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>