<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">I’m wondering if perhaps slf4j could/should handle unwrapping Guice AOP _enhanced_ classes when creating Logger instances?</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Some code simply can not use static class references and has to use obj.getClass() to configure a Logger instance. This can however result in ugly Guice turds in the logger name if the class was enhanced, for example:</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">com.whatever.EventPublisherImpl$$EnhancerByGuice$$</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">… instead of what is generally preferable:</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">com.whatever.EventPublisherImpl</div><div><div class="bloop_container"><div class="bloop_frame"> </div></div></div><br><div class="" id="bloop_sign_1383005838232954880">The AOP stuff here is an impl detail and IMO should leak out into logging context.</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880">I’m wondering if there is a simple/elegant way to handle this in the slf4j-api (and become generally transparent to applications) or if the only good option is to leave it up to applications and then use a custom factory facade like this to unwrap:</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880"><snip></div><div class="" id="bloop_sign_1383005838232954880"><div class="" id="bloop_sign_1383005838232954880"><div class="" id="bloop_sign_1383005838232954880">public class Loggers</div><div class="" id="bloop_sign_1383005838232954880">{</div><div class="" id="bloop_sign_1383005838232954880"> private static final String GUICE_ENHANCED = "$$EnhancerByGuice$$";</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880"> private static boolean isEnhancedSubclass(final Class type) {</div><div class="" id="bloop_sign_1383005838232954880"> return type.getName().endsWith(GUICE_ENHANCED);</div><div class="" id="bloop_sign_1383005838232954880"> }</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880"> public static Logger getLogger(final Class type) {</div><div class="" id="bloop_sign_1383005838232954880"> checkNotNull(type);</div><div class="" id="bloop_sign_1383005838232954880"> if (isEnhancedSubclass(type)) {</div><div class="" id="bloop_sign_1383005838232954880"> return LoggerFactory.getLogger(type.getSuperclass());</div><div class="" id="bloop_sign_1383005838232954880"> }</div><div class="" id="bloop_sign_1383005838232954880"> return LoggerFactory.getLogger(type);</div><div class="" id="bloop_sign_1383005838232954880"> }</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880"> public static Logger getLogger(final Object obj) {</div><div class="" id="bloop_sign_1383005838232954880"> checkNotNull(obj);</div><div class="" id="bloop_sign_1383005838232954880"> return getLogger(obj.getClass());</div><div class="" id="bloop_sign_1383005838232954880"> }</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880"> public static Logger getLogger(final String name) {</div><div class="" id="bloop_sign_1383005838232954880"> return LoggerFactory.getLogger(name);</div><div class="" id="bloop_sign_1383005838232954880"> }</div><div class="" id="bloop_sign_1383005838232954880">}</div></div><div></snip></div><br><span style="font-family:helvetica,arial;font-size:13px"></span><span></span></div><div class="" id="bloop_sign_1383005838232954880">I had considered some sort of magic trickery by adding a facade static binding and then somehow delegating to a real binding, but all of that sounds just too complex.</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880">Anyone have any thoughts?</div><div class="" id="bloop_sign_1383005838232954880"><br></div><div class="" id="bloop_sign_1383005838232954880">—jason</div><div class="" id="bloop_sign_1383005838232954880"><br></div></body></html>