[logback-dev] Question about logback

ceki ceki at qos.ch
Thu Jun 7 18:06:03 CEST 2012


Hi Stephen,

What is the value of ${dataSource.jndi.name}? In a web-app, the value of 
jndiLocation should be prefixed with "java:comp/env/".

Please let us know if this helps,
-- 
Ceki
http://twitter.com/#!/ceki

On 07.06.2012 11:53, stephen.t.chan at asia.bnpparibas.com wrote:
> Hi all,
>
> Thanks for Ceki's reply.
>
> Context.xml
> <Resourcename=/"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
> <connectionSourceclass=/"ch.qos.logback.core.db.JNDIConnectionSource"/>
> <paramname=/"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




More information about the logback-dev mailing list