[logback-user] Context configuration during webapp loading

Eric Schwarzenbach subscriber at blackbrook.org
Wed Aug 22 21:38:58 CEST 2012


I realized I needed to move my ServletContextListener above the Spring 
ContextLoaderListener in my web.xml. However it is still creating a 
application-name_IS_UNDEFINED.log, though an empty (0 byte) one.

Putting a breakpoint on the ContextLoaderListener**doConfigure methods, 
I see it is getting called as a result of the line

LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

(from the manual's example) via org.slf4j.impl.StaticLoggerBinder init 
method  (from the logback-classic.jar).

Any suggestions how I can avoid that? Is there a better way to get the 
LoggerContext?

Eric

On 8/22/2012 2:53 PM, Eric Schwarzenbach wrote:
> I'm trying to use variable substitution for my log file names, using 
> the webapp / context name. (My use case is not literally a shared 
> configuration, but two webapps deployed using copies of the same war 
> with different names...so they each have their own logback.xml, though 
> they are identical). I'm using the example on 
> http://logback.qos.ch/faq.html#sharedConfiguration as my basis, and 
> while it is working, my webapp ends up creating two log files.
>
> First it creates one called application-name_IS_UNDEFINED.log with 
> some of the first messages logged during startup, and then foo.log 
> (where foo is the app name) with all subsequent messages. So it seems 
> to me that the contextInitialized method of ServletContextListener 
> isn't early enough, and that the default logback config is 
> initializing earlier. This is using Tomcat 7, and Java 7.
>
> How can I either hook into the earlier initialization or replace it? 
> Where does that initialization happen? Is that static code?
>
> Thanks,
>
> Eric
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120822/d5ea90c3/attachment.html>


More information about the Logback-user mailing list