I like to use log4jdbc (http://code.google.com/p/log4jdbc/) for logging DB statements within Java JDBC environment. Here is a short instruction how to set it up within a BEA/Oracle weblogic container.
1. Download log4jdbc and slf4j
2. Edit the startup script of you domain and add the following lines
set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS% -Dlocal.url=t3://localhost:7001 -Dlog.dir=D:\logs %LOG4JDBC_OPTIONS%
set LOG4JDBC_OPTIONS=-Dlog4jdbc.drivers=oracle.jdbc.OracleDriver -Dlog4jdbc.sqltiming.warn.threshold=200 -Dlog4jdbc.sqltiming.error.threshold=500
3. This will register a log4jdbc driver for Oracle and the log level WARN will be used for statements longer than 200ms, as well as the ERROR level will be uses for statements which take longer than 500ms
4. You also have to add the necessary jar files to the startup classpath of your weblogic container
set LOG4JDBC_HOME=%DOMAIN_HOME%\log4jdbc
set SAVE_CLASSPATH=%CLASSPATH%;%LOG4JDBC_HOME%\log4jdbc3-1.1.jar;%LOG4JDBC_HOME%\slf4j-api-1.5.0.jar;%LOG4JDBC_HOME%\slf4j-log4j12-1.5.0.jar;%LOG4JDBC_HOME%\log4j-1.2.14.jar;%LOG4JDBC_HOME%\log4j.xml;%LOG4JDBC_HOME%\kdm_conf
as you see we need a log4jdbc, slf4j-api, slf4j-log4j and a log4j jar. The version should fit together and the log4j version has to be at least 1.2.14. The rest of the classpath links to the log4j config. A sample config for log4jdbc is here http://code.google.com/p/log4jdbc/source/browse/trunk/doc/log4j.xml.
5. Last step is the setup of your jdbc configuration. To activate the log4jdbc driver you could just change your current jdbc config file or the data source within the weblogic container. Here is a sample:
Original JDBC config
jdbc:oracle:thin:@hostname:2251@ORACLE_SID oracle.jdbc.OracleDriver
log4jdbc configjdbc:log4jdbc:oracle:thin:@hostname:2251@ORACLE_SID net.sf.log4jdbc.DriverSpy
Thats it.
If you wish to enable loggers, you need to configure them in the "logging.properties" file of the JVM, or another file defined in the "java.util.logging.config.file" system property, in the following way :
AntwortenLöschenjdbc.sqlonly=FINE