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, [email protected] 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@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 *
*[email protected]*
*Sent by: [email protected]*
06/07/2012 04:43 PM
Please respond to
[email protected]
To
[email protected]
cc
Subject
Re: [logback-dev] Question about logback
On 07.06.2012 10:24, [email protected] 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
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-dev