[logback-dev] Question about logback

stephen.t.chan at asia.bnpparibas.com stephen.t.chan at asia.bnpparibas.com
Thu Jun 7 11:53:46 CEST 2012


Hi all,

Thanks for Ceki's reply.

Context.xml 
        <Resource name="jdbc/mydb" auth="Container"
              type="javax.sql.DataSource" username="test" password="test"
                          driverClassName="MySqlDriver" 
              url="jdbc:sqlserver://......"
              maxActive="8" 
              maxIdle="3"
              removeAbandoned = "true"
              removeAbandonedTimeout = "60"
              logAbandoned = "true" 
    />

logback.xml
                <connectionSource class=
"ch.qos.logback.core.db.JNDIConnectionSource">
                        <param name="jndiLocation" value=
"${dataSource.jndi.name}" />
                </connectionSource>

I have tried the 3rd approach as below but error exist. I have checked 
${dataSource.jndi.name}is "jdbc/mydb". Please correct me if I am wrong for 
the setting. Thanks.

11:49:58,808 |-ERROR in 
ch.qos.logback.core.db.JNDIConnectionSource at 19481b2 - Error while getting 
data source javax.naming.NameNotFoundException: Name jdbc is not bound in 
this Context
        at javax.naming.NameNotFoundException: Name jdbc is not bound in 
this Context
        at      at org.apache.naming.NamingContext.lookup(
NamingContext.java:770)
        at      at org.apache.naming.NamingContext.lookup(
NamingContext.java:153)

Stephen




Internet 
ceki at qos.ch
Sent by: logback-dev-bounces at qos.ch
06/07/2012 04:43 PM
Please respond to
logback-dev at qos.ch


To
logback-dev at qos.ch
cc

Subject
Re: [logback-dev] Question about logback






On 07.06.2012 10:24, stephen.t.chan at asia.bnpparibas.com wrote:
> Hi all,
>
 >
 > I am running tomcat6 as http server and specify jdbc connection(with
 > login credential) in context.xml.  Besides, I have defined to use
 > DBAppender in logback.xml to write log to database.  My question is,
 > instead of directly write the login credential in the logback.xml
 > file, how to use property substitution to retrieve the credential from
 > tomcat context.xml?
>
> for example,
>
> <appendername=/"DB"/class=/"com.eqd.iprice.appender.DBAppender"/>
> 
<connectionSourceclass=/"ch.qos.logback.core.db.DriverManagerConnectionSource"/>
>
> <dataSourceclass=/"javax.sql.DataSource"/>
> <driverClass>${driverClass}</driverClass>
> <url>${url}</url>
> <user>${username}</user>
> <password>${password}</password>
> </dataSource>
> </connectionSource>
> </appender>
>
> Those ${XXXX} are retrieved from tomcat context.xml .
>
> Thanks.
>
> Stephen

Hi Stephen,

Here are a couple of approaches you could try.

Approach 1)

If there is a programmatic way to access the variables defined in
context.xml, then you could easily write a custom property definer
[1]. As long as you can access variables defined in context.xml, and
that's a relatively big if, writing a custom property definer should
be a piece of cake.

Approach 2)

If it is not possible to access the variables defined in context.xml,
you can redefine them in web.xml as JNDI variables. Logback can obtain
variables from JNDI.

This approach has the inconvenience of forcing you to define variables
twice, once in content.xml and once in web.xml.

Approach 3)

The best approach in my opinion is to obtain a connection source from
JNDI. The connection source is defined in Tomcat and logback retrieves
and uses it.  See JNDIConnectionSource in DBAppender documentation
[3].

Please keep us posted on your progress.

Cheers,

[1] http://logback.qos.ch/manual/configuration.html#definingPropsOnTheFly
[2] http://logback.qos.ch/manual/configuration.html#insertFromJNDI
[3] http://logback.qos.ch/manual/appenders.html#DBAppender

-- 
Ceki
http://twitter.com/#!/ceki
_______________________________________________
logback-dev mailing list
logback-dev at qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-dev



This message and any attachments (the "message") is
intended solely for the intended addressees and is confidential. 
If you receive this message in error,or are not the intended recipient(s), 
please delete it and any copies from your systems and immediately notify
the sender. Any unauthorized view, use that does not comply with its purpose, 
dissemination or disclosure, either whole or partial, is prohibited. Since the internet 
cannot guarantee the integrity of this message which may not be reliable, BNP PARIBAS 
(and its subsidiaries) shall not be liable for the message if modified, changed or falsified. 
Do not print this message unless it is necessary,consider the environment.

------------------------------------------------------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le "message") 
sont etablis a l'intention exclusive de ses destinataires et sont confidentiels.
Si vous recevez ce message par erreur ou s'il ne vous est pas destine,
merci de le detruire ainsi que toute copie de votre systeme et d'en avertir
immediatement l'expediteur. Toute lecture non autorisee, toute utilisation de 
ce message qui n'est pas conforme a sa destination, toute diffusion ou toute 
publication, totale ou partielle, est interdite. L'Internet ne permettant pas d'assurer
l'integrite de ce message electronique susceptible d'alteration, BNP Paribas 
(et ses filiales) decline(nt) toute responsabilite au titre de ce message dans l'hypothese
ou il aurait ete modifie, deforme ou falsifie. 
N'imprimez ce message que si necessaire, pensez a l'environnement.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-dev/attachments/20120607/16b7ba86/attachment-0001.html>


More information about the logback-dev mailing list