Posted by: Arthur Blake | 2008-04-11

log4jdbc 1.1 released

log4jdbc is a little Java JDBC spy driver that I first open sourced about a year ago.

It can snoop on other JDBC drivers and log all the goodies going on with your database under the hood– SQL, timing info and more!

I just released the 1.1 final release today. It has some significant improvements over the 1.0 release which came out last year around this time. Most notably, it uses the SLF4J logging system (instead of log4j) so it’s much more portable as to which logging system you can use.

Hope you enjoy using it and please send me feedback if you like it (or hate it).



  1. Hi guy,
    great work! Please add publish your work into a maven repository.

  2. I’ve had several requests for that.
    It’s on my TODO list!

  3. Good job. Do you have any plans on adding a log4jdbc DataSource? We do most of our development outside of a JEE container and have a JUnit test platform that instantiates the DataSource(s).

  4. At this time log4jdbc does not have direct support for data sources. It is one of the features I would like to add in the future

    However, there is an alternative way to use log4jdbc that has worked really well for some people using data sources:

    If you have a central location in your code where your application obtains connections, you can simply wrap the Connection object returned. Example:

    // get connection from datasource
    Connection conn = dataSource.getConnection();

    // wrap the connection with log4jdbc
    conn = new net.sf.log4jdbc.ConnectionSpy(conn);

    // now use Connection as normal (but it will be audited by log4jdbc)

    This also has the extra benefit of not requiring the log4jdbc driver to be initialized.

    I hope this might be a solution for you.

  5. hi!

    i want to ask about the sqltiming in these logs.

    are they taken from the execution time on the application server side or the database server side?

  6. The timing is taken on the application side.

  7. Nice library. In jdbc.sqlonly output, what is the number preceding the sql (i.e. 1, 2, 3, …) meant to signify? At first I thought it might be the sequence of sql calls in relation to a transaction, but that doesn’t seem to be the case.

  8. It’s the connection number. The number is incremented each time a new connection is requested. I’ve used it in the past to hunt down connection pool leaks and issues. I’ve added some more features related to that in the upcoming 1.2 release.

  9. I also need the DataSource feature. Do you think it is more complicated than providing a stub? You could maybe just add the original driver class to a system property or in the url.

  10. I just made a quick hack to wrap the connections and it works pretty well. It is a bit ugly. If you need the source let me know and I will clean up, otherwise I would like to avoid the work:)

  11. Hi Arthur
    Very nice utility. worked right out of the box. I have a question/comment. It would be nice if there would be a way of providing set of queries/stored procs, where parameters should be masked. For example, during profiling, if authentication is taking a long time, it’s might not be a good idea to print out user’s password credentials.
    what do you think about that?

  12. Sent the sources for XADataSource, XAResource and XAConnection to Arthur.

  13. @Leonard: yeah, sounds like it would be a useful feature, especially for people who want to use log4jdbc as an auditing tool in a secure enterprise environment. It’s not something I particularly need right now but if you submit high quality patch I might consider adding it.

    @Bernd: thanks for the changes. I don’t have time to look at it right away, but I hope to add data source support into 1.2 as it’s one of the most requested features. Maven support is the other feature that people seem to want a lot.

    If anyone wants to play with 1.2 alpha 1 it’s checked into subversion– I just haven’t had time to cut a build!

  14. Logging queries with Hibernate and Log4jdbc :

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: