JDBC logging to file

前端 未结 6 564
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 02:43

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 a

6条回答
  •  隐瞒了意图╮
    2020-12-06 02:54

    I'm measuring the performance of my jdbc driver, this is a Tandem Non/Stop DB, and just setting the LogWriter in the DriverManager like this:

            try {
                // This will load the JDBC Driver
                Class.forName("com.tandem.t4jdbc.SQLMXDriver");
                // Here you will enable the Logging to a file.
                DriverManager.setLogWriter(new PrintWriter(new File("log/dbcLog.log")));
            } catch (ClassNotFoundException e) {
                _logger.error(e.toString());
            }
    

    The logging on Queries started working.


    Just as an update, I also found out that for some JDBC drivers the solution can NOT be accomplished programatically (by code changes). For example, I'm using a JDBC driver for Tandem t4 driver, and even though I added all what the manuals said about enabling JDBC tracing, it just worked from time to time and just for Queries..

    Then, I was told to use just the following parameter (as a VM Option):

    -Dt4sqlmx.T4LogFile=t4sqlmx.log -Dt4sqlmx.T4LogLevel=FINE
    

    And it just simple started working..

提交回复
热议问题