[logback-user] Configuring jndi db access in tomcat5.5: some thoughts

Ceki Gulcu listid at qos.ch
Thu Jul 17 20:29:08 CEST 2008



Diego Louzán wrote:
> The last couple of days I've been learning about SLF4J and Logback. IMHO 
> this is a great piece of software.

Thanks.

> One of my needs was to configure logging to a JNDI shared database 
> inside tomcat 5.5. I followed the directions outlined in 
> http://logback.qos.ch/manual/appenders.html for configuring the 
> DBAppender with a JNDIConnectionSource.
> 
> The example code in the manual is like this:
> 
> <connectionSource class="ch.qos.logback.core.db.JNDIConnectionSource">
>    <param name="jndiLocation" value="jdbc/MySQLDS" />
>    <param name="username" value="myUser" />
>    <param name="password" value="myPassword" />
> </connectionSource>
> 
> (BTW, the "username" param in the documentation is wrong, it must be 
> "user").

If it's not too much to ask, could you please enter a bug report regarding this 
problem?


Actually, you might want to reference this whole thread as from what I could 
understand, there are multiple issues involved.


[snip]

> As you can see, tomcat references a JCL logger in 
> "org.apache.catalina.core.ContainerBase.getLogger" just when first 
> loading the webapp. This triggers logback initialization, and when the 
> JNDIConnectionSource tries to get a reference to the DataSource, it 
> finds nothing.

Interesting problem. One way to solve it would be to perform logback 
configuration in two stages. In the first stage, you would configure logback as 
usual, using logback.xml. In the second, you would use another config file, say 
logback-db.xml and invoke Joran after tomcat has been initialized.

Here is sample code:

   LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
   URL url = Loader.getResource("logback-db.xml", classLoader);
   JoranConfigurator configurator = new JoranConfigurator();
   LoggerContext loggerContext = ()
   configurator.setContext(lc);
   configurator.doConfigure(url);


> I found a reference to a similar problem with JNDI contexts in the old 
> bugzilla tracker (http://marc.info/?l=logback-dev&m=119005116732589&w=2) 
> but although I tried locating this bug report in the new JIRA tracker I 
> could not find it. Maybe it got lost during the migration?

It's here:
http://jira.qos.ch/browse/LBCLASSIC-30

I found it by going to jira.qos.ch, FIND ISSUES and entering 96 as the bugzilla 
id to search for (at the bottom of the page). Entering "ContextSelectors" as the
query text also yields valid results. So, it looks like the migration was OK.

> At the moment I'm still trying to fully understand the codebase. Do you 
> figure out any solution to the problem?

See above.

> I'm sorry for such a lengthy message. Hope this info helps the project.
> Regards and keep up the good work.

Thanks,

> Diego.

-- 
Ceki Gülcü

QOS.ch is looking to hire talented developers located in Switzerland
to work on cutting-edge software projects. If you think you are
qualified, then please contact ceki at qos.ch.


More information about the Logback-user mailing list