Monday, July 30, 2007

Java Logging with JDBC

I hate debuggers! Not that they don't do the job they are meant for but I have always found them to be a big waste of time in the initial stages of debugging a code issue. I prefer to use a logger mechanism and then jump into the debugger for detailed runtime data only if I cannot track down the problem theoretically using my logs.

Anyway, I work in an environment where all development is done remotely and I don't have much control over the servers that actually run my code. I do have access to the database for the different environments and can create tables etc. I normally use Log4J for my logging needs but adding that manually to my development environment is a pain. So I finally turned to Java's logging API and found that it fell way below my Log4J based expectations. Firstly it did not give me much control over the logging configuration. Secondly, there was no JDBC based logging mechanism available. Well I decided to roll my own.

Features:

  • JDBC support for logging
  • Custom logging configuration (including the JDBC support configuration). Can be used for creating any custom configuration and not just the JDBC support.
  • Message caching. This implementation caches messages up to a configured threshold. All cached messages are logged to the database as soon as the threshold is reached.
  • Open source. Use, modify, distribute (as long as you retain the copyright notice below). Suggestions, bug reports welcome.
Pending Features (Stuff I would like to add but haven't yet):
  • Configurable Asynchronous logging: So that we don't block the main thread making the logging calls.
  • Performance Tunning: The current release is not optimized and has numerous areas which can benefit from some performance tunning.
I am releasing the source code to my JDBC support for Java's logging APIs. You can download the source code here. You may use this code for any purpose, as long as you leave the copyright notice attached. Use this code at your own risk.

See the readme.txt file in the zip archive for details of how to use the code. The JavaDoc is also a good place to look for further details. The source code is of course the best source for implementation and usage details.

-------------------------------------------------------------------------------
Copyright (C) 2006 Gautam Satpathy (gautam@satpathy.in)
You may use this code for any purpose, as long as you leave the copyright notice
attached. Use this code at your own risk.
-------------------------------------------------------------------------------

No comments: