I’m wondering if perhaps slf4j could/should handle unwrapping Guice AOP 
_enhanced_ classes when creating Logger instances?

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:

com.whatever.EventPublisherImpl$$EnhancerByGuice$$

… instead of what is generally preferable:

com.whatever.EventPublisherImpl

The AOP stuff here is an impl detail and IMO should leak out into logging 
context.

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:

<snip>
public class Loggers
{
  private static final String GUICE_ENHANCED = "$$EnhancerByGuice$$";

  private static boolean isEnhancedSubclass(final Class type) {
    return type.getName().endsWith(GUICE_ENHANCED);
  }

  public static Logger getLogger(final Class type) {
    checkNotNull(type);
    if (isEnhancedSubclass(type)) {
      return LoggerFactory.getLogger(type.getSuperclass());
    }
    return LoggerFactory.getLogger(type);
  }

  public static Logger getLogger(final Object obj) {
    checkNotNull(obj);
    return getLogger(obj.getClass());
  }

  public static Logger getLogger(final String name) {
    return LoggerFactory.getLogger(name);
  }
}
</snip>

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.

Anyone have any thoughts?

—jason

_______________________________________________
slf4j-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/slf4j-user

Reply via email to