Hello,
I tried to set this up, and the log file is created, but nothing
is ever written to it. My servlet, which gets loaded at startup, looks
like this:
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.FileOutputStream;
import java.io.PrintWriter;
public class LoaderServlet extends HttpServlet {
public void init() {
System.out.println(new java.util.Date() + ": " +
this.getClass().getName() +
": setting Datasource log");
try {
DataSource dataSource = (DataSource) new
InitialContext().lookup("jdbc/oracle");
dataSource.setLogWriter(new PrintWriter(new
FileOutputStream("log/jdbc.log",true)));
} catch (Exception e) {
System.out.println(new java.util.Date() + ": " +
this.getClass().getName() +
": unable to create Datasource log: " + e.getMessage());
}
}
}
The message gets printed to the log at startup, telling me that init()
method is getting called, and that no exceptions are being thrown. The
file is created, but nothing ever gets printed to it. I have looked at
the Datasource class, and I don't see any methods to turn logging on.
Any idea why nothing ever gets printed to the log?
Bill
I am seeing
Attila Bodis wrote:
> Bill,
>
> I do just that, i.e. open the log file for writing in the init() method of a
> dumb servlet that gets preloaded at startup. I pick up the path/filename of
> the log file from a context-param which I set in web.xml (and override in
> orion-web.xml if necessary).
>
> A better way to do all this would be to use log4j, but I haven't had a
> chance to look into it in any depth.
>
> Hope this helps,
>
> Attila
>
>
>
> ----- Original Message -----
> From: "Bill Clinton" <[EMAIL PROTECTED]>
> To: "Orion-Interest" <[EMAIL PROTECTED]>
> Sent: Friday, July 20, 2001 6:50 AM
> Subject: Re: Datasource Question - is there a way to setup a JDBC log file?
>
>
>
>> Attila,
>> Thanks alot. I believe this is what I need, but I am going to
>> trouble you with one more question: Where would you recommend doing
>> this in a web application? I was hoping that there would be somewhere
>> to set a log file in the definition of the datasource. I assume I only
>> need to set the logWriter once, so could I do it in the init method of a
>> dumb servlet that gets preloaded? Or is there a better time and place to
>> set the logWriter?
>>
>> Thanks again for your response
>> Bill
>>
>> Attila Bodis wrote:
>>
>>
>>> Bill,
>>>
>>> // Use JNDI lookup to locate the data source:
>>> InitialContext ctx = new InitialContext(System.getProperties());
>>> DataSource ds = (DataSource)ctx.lookup(dsName);
>>>
>>> // Have the connection pool log to the specified log file:
>>> ds.setLogWriter(myPrintWriter);
>>>
>>> Where dsName is the name of your datasource (as specified in
>>> data-sources.xml) and myPrintWriter is a java.io.PrintWriter object
>>
> which
>
>>> writes to the log file of your choice.
>>>
>>> Hope this helps,
>>>
>>> Attila
>>>
>>>
>>> ----- Original Message -----
>>> From: "Bill Clinton" <[EMAIL PROTECTED]>
>>> To: "Orion-Interest" <[EMAIL PROTECTED]>
>>> Sent: Wednesday, July 18, 2001 4:37 PM
>>> Subject: Datasource Question - is there a way to setup a JDBC log file?
>>>
>>>
>>>
>>>
>>>> Hello,
>>>> I am curious on how to set up logging for JDBC. I thought there
>>>> would be a parameter in the data-source definition that would allow
>>>> logging. Does this exist?
>>>>
>>>> Bill
>>>>
>>>> btw: I am using oracle
>>>>
>>>>
>>>>
>>>
>>
>>