[logback-dev] [JIRA] Commented: (LBCORE-51) LoggerFactory doesnt respect custom ContextSelector

Ceki Gulcu (JIRA) noreply-jira at qos.ch
Mon Jun 9 15:48:11 CEST 2008


    [ http://jira.qos.ch/browse/LBCORE-51?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10586#action_10586 ] 

Ceki Gulcu commented on LBCORE-51:
----------------------------------

>From the preliminary tests I have conducted, it appears that StaticLoggerBinder can properly install custom selectors, and in particular your LoggerContextFilter. 

Looking at LoggerContextFilter.getLoggerContext() method with no arguments, I notice that "if(contextName==null)" will always be true, and the method will always return defaultContext, which is probably not what you want. In your implementation, you would probably want to key the hashMap by the class loader for the current thread. For a web-application, the thread context class loader (TCCL) is the same throughout the application. More generally  however, different modules of the same application may have different class loaders. For example, the TCCL for EJBs may not be the same as the TCCL for each web-app, even if they are all packages together. JSPs may also be loaded by different TCCL.

In summary, doing context selection by TCCL is considered a bad idea. JNDI is the recommended approach.

Having said that, I think the LoggerFactory class in SLF4J does not really support context selectors even for logback. I will look into this.


> LoggerFactory doesnt respect custom ContextSelector
> ---------------------------------------------------
>
>                 Key: LBCORE-51
>                 URL: http://jira.qos.ch/browse/LBCORE-51
>             Project: logback-core
>          Issue Type: Bug
>         Environment: Windows XP64, Java 6, Red5 v0.7.1-dev, Logback 0.9.9, Slf4j 1.5.0
>            Reporter: Paul Gregoire
>            Assignee: Logback dev list
>
> I have found that calling LoggerFactory.getLogger(xxxx) does not make calls to my custom context selector. I expect to see a call to getLoggerContext() but I dont. Do I need to create my own LoggerFactory impl to get my web context apps and red5 apps to use their own Loggers?
> Main Red5 trunk (dev)
> http://svn1.cvsdude.com/osflash/red5/java/server/trunk/
> My logger implementations
> http://svn1.cvsdude.com/osflash/red5/java/server/trunk/src/org/red5/logging/
> Example JSP I used to test the log context selection
> <%@page import="org.slf4j.Logger,org.slf4j.LoggerFactory,org.slf4j.impl.StaticLoggerBinder,ch.qos.logback.classic.LoggerContext,org.red5.logging.LoggingContextSelector"%>
> <html>
> <body>
> <%
> //
> Logger log = LoggerFactory.getLogger("TestJsp");
> log.info("This is a test log entry from a web context");
> //
> LoggingContextSelector selector = (LoggingContextSelector) StaticLoggerBinder.SINGLETON.getContextSelector();		
> LoggerContext ctx = selector.getLoggerContext(mywebappcontextname);
> Logger log2 = ctx.getLogger("TestJsp");
> log2.info("This is a test log entry from a web context attempt 2");
> %>
> </body>
> </html>
> The first log goes to the "default" logger context and the second goes to the correct one. I also implemented the Servlet filter and context listener for this tested context.
> Anything I can do to help, please let me know.. I am getting extremely frustrated with this logging stuff and I'm sure our users are as well.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the logback-dev mailing list