<font size=2 face="sans-serif">Hi all,</font>
<br>
<br><font size=2 face="sans-serif">Thanks for Ceki's reply.</font>
<br>
<br><font size=2 face="sans-serif">Context.xml </font>
<br><font size=2 face="Courier New"> </font><font size=2 color=#008080 face="Courier New"><</font><font size=2 color=#3f8080 face="Courier New">Resource</font><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">name</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"jdbc/mydb"</i></font><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">auth</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"Container"</i></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">type</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"javax.sql.DataSource"</i></font><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">username</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"test"</i></font><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">password</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"test"</i></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">driverClassName</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"MySqlDriver"</i></font><font size=2 face="Courier New">
</font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">url</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"jdbc:sqlserver://......"</i></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">maxActive</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"8"</i></font><font size=2 face="Courier New">
</font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">maxIdle</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"3"</i></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">removeAbandoned</font><font size=2 face="Courier New">
= </font><font size=2 color=#4200ff face="Courier New"><i>"true"</i></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">removeAbandonedTimeout</font><font size=2 face="Courier New">
= </font><font size=2 color=#4200ff face="Courier New"><i>"60"</i></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">logAbandoned</font><font size=2 face="Courier New">
= </font><font size=2 color=#4200ff face="Courier New"><i>"true"</i></font><font size=2 face="Courier New">
</font>
<br><font size=2 face="Courier New"> </font><font size=2 color=#008080 face="Courier New">/></font>
<br>
<br><font size=2 color=#008080 face="Courier New">logback.xml</font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#008080 face="Courier New"><</font><font size=2 color=#3f8080 face="Courier New">connectionSource</font><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">class</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"ch.qos.logback.core.db.JNDIConnectionSource"</i></font><font size=2 color=#008080 face="Courier New">></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#008080 face="Courier New"><</font><font size=2 color=#3f8080 face="Courier New">param</font><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">name</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"jndiLocation"</i></font><font size=2 face="Courier New">
</font><font size=2 color=#800080 face="Courier New">value</font><font size=2 face="Courier New">=</font><font size=2 color=#4200ff face="Courier New"><i>"${dataSource.jndi.name}"</i></font><font size=2 face="Courier New">
</font><font size=2 color=#008080 face="Courier New">/></font>
<br><font size=2 face="Courier New">
</font><font size=2 color=#008080 face="Courier New"></</font><font size=2 color=#3f8080 face="Courier New">connectionSource</font><font size=2 color=#008080 face="Courier New">></font>
<br>
<br><font size=2 face="sans-serif">I have tried the 3rd approach as below
but error exist. I have checked </font><font size=2 color=#4200ff face="Courier New"><i>${dataSource.jndi.name}</i></font><font size=2 face="sans-serif">is
"jdbc/mydb". Please correct me if I am wrong for the setting.
Thanks.</font>
<br>
<br><font size=2 face="Courier New">11:49:58,808 |-ERROR in ch.qos.logback.core.db.JNDIConnectionSource@19481b2
- Error while getting data source </font><font size=2 color=#000080 face="Courier New"><u>javax.naming.NameNotFoundException</u></font><font size=2 face="Courier New">:
Name jdbc is not bound in this Context</font>
<br><font size=2 face="Courier New"> at
</font><font size=2 color=#000080 face="Courier New"><u>javax.naming.NameNotFoundException</u></font><font size=2 face="Courier New">:
Name jdbc is not bound in this Context</font>
<br><font size=2 face="Courier New"> at
at org.apache.naming.NamingContext.lookup(</font><font size=2 color=#000080 face="Courier New"><u>NamingContext.java:770</u></font><font size=2 face="Courier New">)</font>
<br><font size=2 face="Courier New"> at
at org.apache.naming.NamingContext.lookup(</font><font size=2 color=#000080 face="Courier New"><u>NamingContext.java:153</u></font><font size=2 face="Courier New">)</font>
<br>
<br><font size=2 face="Courier New">Stephen</font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=33%><font size=4 face="helv"><b>Internet </b></font>
<br><font size=1 face="sans-serif"><b>ceki@qos.ch</b></font>
<p><font size=1 face="sans-serif"><b>Sent by: logback-dev-bounces@qos.ch</b></font>
<p><font size=1 face="sans-serif">06/07/2012 04:43 PM</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
logback-dev@qos.ch</font></div></table>
<br>
<td width=66%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">logback-dev@qos.ch</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [logback-dev] Question about logback</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2>On 07.06.2012 10:24, stephen.t.chan@asia.bnpparibas.com
wrote:<br>
> Hi all,<br>
><br>
><br>
> I am running tomcat6 as http server and specify jdbc connection(with<br>
> login credential) in context.xml. Besides, I have defined to
use<br>
> DBAppender in logback.xml to write log to database. My question
is,<br>
> instead of directly write the login credential in the logback.xml<br>
> file, how to use property substitution to retrieve the credential
from<br>
> tomcat context.xml?<br>
><br>
> for example,<br>
><br>
> <appendername=/"DB"/class=/"com.eqd.iprice.appender.DBAppender"/><br>
> <connectionSourceclass=/"ch.qos.logback.core.db.DriverManagerConnectionSource"/><br>
><br>
> <dataSourceclass=/"javax.sql.DataSource"/><br>
> <driverClass>${driverClass}</driverClass><br>
> <url>${url}</url><br>
> <user>${username}</user><br>
> <password>${password}</password><br>
> </dataSource><br>
> </connectionSource><br>
> </appender><br>
><br>
> Those ${XXXX} are retrieved from tomcat context.xml .<br>
><br>
> Thanks.<br>
><br>
> Stephen<br>
<br>
Hi Stephen,<br>
<br>
Here are a couple of approaches you could try.<br>
<br>
Approach 1)<br>
<br>
If there is a programmatic way to access the variables defined in<br>
context.xml, then you could easily write a custom property definer<br>
[1]. As long as you can access variables defined in context.xml, and<br>
that's a relatively big if, writing a custom property definer should<br>
be a piece of cake.<br>
<br>
Approach 2)<br>
<br>
If it is not possible to access the variables defined in context.xml,<br>
you can redefine them in web.xml as JNDI variables. Logback can obtain<br>
variables from JNDI.<br>
<br>
This approach has the inconvenience of forcing you to define variables<br>
twice, once in content.xml and once in web.xml.<br>
<br>
Approach 3)<br>
<br>
The best approach in my opinion is to obtain a connection source from<br>
JNDI. The connection source is defined in Tomcat and logback retrieves<br>
and uses it. See JNDIConnectionSource in DBAppender documentation<br>
[3].<br>
<br>
Please keep us posted on your progress.<br>
<br>
Cheers,<br>
<br>
[1] </font></tt><a href=http://logback.qos.ch/manual/configuration.html#definingPropsOnTheFly><tt><font size=2>http://logback.qos.ch/manual/configuration.html#definingPropsOnTheFly</font></tt></a><tt><font size=2><br>
[2] </font></tt><a href=http://logback.qos.ch/manual/configuration.html#insertFromJNDI><tt><font size=2>http://logback.qos.ch/manual/configuration.html#insertFromJNDI</font></tt></a><tt><font size=2><br>
[3] </font></tt><a href=http://logback.qos.ch/manual/appenders.html#DBAppender><tt><font size=2>http://logback.qos.ch/manual/appenders.html#DBAppender</font></tt></a><tt><font size=2><br>
<br>
-- <br>
Ceki<br>
</font></tt><a href=http://twitter.com/#!/ceki><tt><font size=2>http://twitter.com/#!/ceki</font></tt></a><tt><font size=2><br>
_______________________________________________<br>
logback-dev mailing list<br>
logback-dev@qos.ch<br>
</font></tt><a href="http://mailman.qos.ch/mailman/listinfo/logback-dev"><tt><font size=2>http://mailman.qos.ch/mailman/listinfo/logback-dev</font></tt></a><tt><font size=2><br>
</font></tt>
<br><font face="monospace"><br>
<br>
This message and any attachments (the "message") is<br>
intended solely for the intended addressees and is confidential. <br>
If you receive this message in error,or are not the intended recipient(s), <br>
please delete it and any copies from your systems and immediately notify<br>
the sender. Any unauthorized view, use that does not comply with its purpose, <br>
dissemination or disclosure, either whole or partial, is prohibited. Since the internet <br>
cannot guarantee the integrity of this message which may not be reliable, BNP PARIBAS <br>
(and its subsidiaries) shall not be liable for the message if modified, changed or falsified. <br>
Do not print this message unless it is necessary,consider the environment.<br>
<br>
------------------------------------------------------------------------------------------<br>
<br>
Ce message et toutes les pieces jointes (ci-apres le "message") <br>
sont etablis a l'intention exclusive de ses destinataires et sont confidentiels.<br>
Si vous recevez ce message par erreur ou s'il ne vous est pas destine,<br>
merci de le detruire ainsi que toute copie de votre systeme et d'en avertir<br>
immediatement l'expediteur. Toute lecture non autorisee, toute utilisation de <br>
ce message qui n'est pas conforme a sa destination, toute diffusion ou toute <br>
publication, totale ou partielle, est interdite. L'Internet ne permettant pas d'assurer<br>
l'integrite de ce message electronique susceptible d'alteration, BNP Paribas <br>
(et ses filiales) decline(nt) toute responsabilite au titre de ce message dans l'hypothese<br>
ou il aurait ete modifie, deforme ou falsifie. <br>
N'imprimez ce message que si necessaire, pensez a l'environnement.</font>