You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Ralph Goers (JIRA)" <ji...@apache.org> on 2012/05/01 06:57:44 UTC

[jira] [Commented] (LOG4J2-42) Improving log4j so it can easily be used with servlet logging

    [ https://issues.apache.org/jira/browse/LOG4J2-42?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13265660#comment-13265660 ] 

Ralph Goers commented on LOG4J2-42:
-----------------------------------

LogManager.getLogger() passes the FQCN of the LogManager and thus determines the class that invoked it. ClassLoaderContextSelector uses this information to associate the Logger instance with the LoggerContext associated with the caller's ClassLoader. Unfortunately, the class itself isn't stored currently.
                
> Improving log4j so it can easily be used with servlet logging
> -------------------------------------------------------------
>
>                 Key: LOG4J2-42
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-42
>             Project: Log4j 2
>          Issue Type: Wish
>          Components: API
>            Reporter: Curt Arnold
>
> On May 30, 2010, at 11:49 AM, Thorbjørn Ravn Andersen wrote:
> 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?
> [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!"
> The follows at http://thread.gmane.org/gmane.comp.jakarta.log4j.devel/15576

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

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