First, log4j is a logging library for Java, and a very popular one at that. Basically, rather than just putting a bunch of print statements in your code, you can use log4j to handle logging in a highly structured and configurable way. The best thing about it is that you can sprinkle all sorts of logging statements in your code, and then turn most of them off when you have the bugs fixed and it’s time to deploy the application.

For a year now, my relationship with log4j has been completely harmonious. I’ve basically just used it to send all of its log messages to the console, and the only settings I’ve tweaked have been the log format (more detailed in the dev environment than in production) and what level of logging is turned on for various parts of my application. For example, I want to see every message for code I wrote, but only errors from external code that uses log4j (many Jakarta packages).

For about a week, I’ve been trying to take log4j to the next level. I’m trying to use the SMTP logger to have log4j send error messages from production to me via email, so I can find out things are broken before people start complaining about them. This ought to be relatively straightforward, but it has turned out to be a huge struggle, and frankly I’m a bit tired of it. log4j works like you’d expect it to — it’s easy to configure to do simple stuff, but your configuration can grow complex fairly rapidly. The problem is that the docs for log4j are poor, so it requires tons of trial and error work to figure out what’s going on. Then there’s the part where log4j seems to be behaving erratically, so I’m not sure whether the problems are due to my misconfiguration of log4j or something else.

I think that this may be the final straw that forces me to figure out how to run Tomcat within a debugger so that I can step through the log4j code and determine exactly what’s going wrong. I could abandon the whole project and leave things as they are, but that’s not my nature. One side benefit is that I’m strongly considering writing and posting my own guide to log4j just so I don’t forget everything I have managed to figure out.