[slf4j-user] [slf4j-dev] Plan for SLF4J 2.0

Thorbjoern Ravn Andersen ravn at runjva.com
Sun May 30 20:43:12 CEST 2010


Den 06/03/10 14.48, Ceki Gülcü skrev:
>
> Are there any other major items? Is everyone OK with requiring JDK
> 1.5 in SLF4J 2.0?
There is one more thing that I would really like to see in slf4j 2.0, 
namely the ability for a servlet to log to a servlet container using 
slf4j.   Currently that cannot be done, because there is no way for the 
code asking for the logger to pass a "this" reference to the logging 
framework.

I would suggest that in SLF4J 2.0 the LoggerManager.getLogger() 
signature is changed to accept the class (as now), and a varargs of 
Objects.  The objects are passed to the appender when needing to do the 
actual logging, allowing a ServletLoggerAppender to look for any object 
extending GenericServlet and invoke its log method.

For client code it would mean that the logger object was retreived with

   org.sfl4j.Logger log = 
org.slf4j.LoggerFactory.getLogger(this.getClass(), this);


We might even consider making the rule in slf4j 2.0 that "the name of 
the logger is the full name of the class of the first object"[2].  In 
that case we could make do with:

   org.sfl4j.Logger log = org.slf4j.LoggerFactory.getLogger(this);

This would most likely also result in much other code being cleaner by 
allowing to drop the "getClass()" clause.

What do you think?







[1] 
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/GenericServlet.html#log%28java.lang.String%29

[2] For backwards compatability instances of Class should be treated 
slightly different :)

-- 
   Thorbjørn Ravn Andersen  "...plus... Tubular Bells!"



More information about the slf4j-user mailing list