I need to log all the queries to an Oracle database in my project to a log file.
What would be a good solution to achieve this? Some sample usage would be appreciated.
I have looked at SLF4J with jdbcdslog, but I’m not sure how I can log to a file with it. Moreover, I would need to “filter” some of the logs (because I don’t need to know when some getxxxx method get’s invoked)
Preferably, I’d prefer to use java.util.logging but it is not a requirement.
Thanks.
** UPDATE **
I found this Oracle article, however it does not really tell how to programatically do the same thing.
After much reading, this is how I got things working :
NOTE : Fore more information, read the Oracle Diagnosability in JDBC document
And here’s the magic :
The properties file (from Oracle’s documentation) :
Basically, this is where the handlers are declared
Declares the
ConsoleHandlerto be used by Oracle’s JDBC driver. Any and any number of handlers can be declared here, one per line, with the class’ full qualified name :One can provide their own custom made handlers with the same rule. The following lines are to setup the handler
will call the methode
setLevel(Level.INFO)of theConsoleHandlerhandler instance.will call the method
setFoo("Bar")of theMyHandlerhandler instance. And that’s it.Happy logging!