Log SQL that is communicated with the database

前端 未结 1 875
广开言路
广开言路 2021-01-16 09:21

I am working on a SQL Logger for my web application. I want to be able to Log the SQL query that is fired by user-interaction with the GUI. I\'m working in a Spring environm

相关标签:
1条回答
  • 2021-01-16 10:18

    i use jdbcdslog-exp for cases like this.

    add jdbcdslog-1.0.6.2.jar to classpath.

    add categories to log4j configuration (set INFO for ResultSetLogger too if you want - beware of OutOfMemory)

    <category name="org.jdbcdslog.StatementLogger">
      <priority value="INFO"/>
    </category>  
    <category name="org.jdbcdslog.ResultSetLogger">
      <priority value="FATAL"/>
    </category>
    

    if you need to switch statement logging by runtime you can start your log4j with

    PropertyConfigurator.configureAndWatch("log4j.xml", 60000);
    

    change your jdbc connection parameters (here example for hsql in jboss)

    from

    <connection-url>jdbc:hsqldb:hsql://localhost:1801</connection-url>
    <driver-class>org.hsqldb.jdbcDriver</driver-class>
    

    to

    <connection-url>jdbc:jdbcdslog:hsqldb:hsql://localhost:1801;targetDriver=org.hsqldb.jdbcDriver</connection-url>
    <driver-class>org.jdbcdslog.DriverLoggingProxy</driver-class>
    
    0 讨论(0)
提交回复
热议问题