Friday, May 21, 2010

How to Turn on Ojdbc Driver Debug Logging

It had been a while since I turned on ojdbc trace logging, so I had to look it up. Found a great article called Turning on Oracle Driver Tracing by Kualigan and added my notes below. I didn't use the Sun Java Logging API part of it.

If you need to turn on Oracle JDBC driver debug or trace logging, you first need to install the ojdbc driver "g" jar provided by Oracle (for example, ojdbc14_g.jar).

If using Maven 2 and you don't want to make changes to your pom.xml(s), you could just swap out the version in your local repo with the debug version, but that may cause you later to accidentally include the debug version in another project, so I just changed the version in my pom.xml to a version I knew I didn't have called "9.2.0.8debug" (because I downloaded the ojdbc v9.2.0.8 debug driver).

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
            <!--<version>10.2.0.4.0</version>-->
            <version>9.2.0.8debug</version>
            <exclusions>
              <exclusion>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>catalina</artifactId>
              </exclusion>
            </exclusions>
        </dependency>

Then when I rebuilt, I used the command Maven 2 told me to use to manually install that jar.

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=9.2.0.8debug -Dpackaging=jar -Dfile=/Users/myuser/Downloads/ojdbc14_g.jar

Then if you are trying to trace in a functional test run by Maven, you modify pom.xml's surefire plugin config in its build plugins to turn on trace logging and specify a Java logging API config file:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <reportFormat>brief</reportFormat>
                    <useFile>false</useFile>
                    <systemProperties>
                        <property>
                            <name>oracle.jdbc.Trace</name>
                            <value>true</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>

More info:
* Turning on Oracle Driver Tracing

No comments: