logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorbjørn Ravn Andersen <nospam0...@gmail.com>
Subject Improving log4j so it can easily be used with servlet logging
Date Sun, 30 May 2010 16:49:07 GMT
There is one more thing that I would really like to see in log4j 2.0, 
namely the ability for a servlet to log to a servlet container using 
log4j (and in slf4j too but that is a different story).   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 log4j 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 
similar to:

    Logger log = Logger.getLogger(this.getClass(), this);

We might even consider making the rule in log4j 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:

   Logger log = Logger.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?


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

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

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message