Java logging is fundamentally broken. This is hard fact, not a point of view. Logging is broken, and has been for years.
How is it broken, you ask? Let me count the ways:
System.out, then logged with a severity of INFO regardless of the original severity. Glassfish also uses a really ugly multi-line logging format as default. I’d really like to change that if I could only figure out how.In short, I have spent way to much time just getting simple logging working through the years, and now I’ve had just about enough. Think of the man-hours lost, what we could be doing instead of fiddling with log4j.properties and commons-logging.properties! Why do we put up with this?
The basic principles of logging are sound, but it’s too late. There are simply too many logging frameworkds out there, each one making the situation a little bit worse. Commons Logging was bad enough. Log4J fractured the market, and Sun cemented the situation by introducing the badly designed JDK logging package.
Logging meta-frameworks isn’t really helping the situation. The ship has sailed. We don’t need more frameworks, we need less of them. The ideal situation would be exactly one logging framework (that doesn’t suck), that would be the obvious choice for most projects. As it stands now all open source projects use a different one, each incompatible with each others but offering ‘helpful’ and ‘seamless’ integration that never seems quite to work.
Last time I checked the dependencies for our main webapp at work included multiple versions of Log4J, Commons Logging, Slf4J, and problably Logback and a few others I’ve missed as well. Have fun working out the classloader issues there!
I dreamt this up at work the other day, and this is all purely hypothetical, but I do believe someone should make something like this.
Anyway, WoodChipper (or whatever it will be called, I choose the name since it is a machine that disintegrates logs) is a java utility that goes through all the jar files on your class path and uses sophisticated byte code manipulation to replace all references to Commons Logging, Log4J, JDK logging, etc. with System.out.println(). Ideally this could be done at runtime, or as a maven plugin.
I know some people would argue it’d better to make it all Slf4J instead, but then you’re kind of missing the point. I’ve had enough of logging. I don’t want to spend another minute configuring a logging framework, and I don’t see why I should have to. I’m declaring logging bancruptcy.
Writing to stdout isn’t bad. At least the results can be piped, greped and redirected using standard Unix tools.
Today I started thinking that maybe what we need is a new sort of Open Source license, kind of like an inverted GPL. It would state that you’re free to use my code pretty much anyway you like, just as long as the finished product does not depend on a logging framework. Any transgressions would be punishable by catapult.
Extreme measures, perhaps. But if that’s what it takes to get people to stop using Commons Logging, it may well be worth it in the end.