Stubbisms – Tony’s Weblog

July 27, 2008

It’s time to let go of Commons Logging – Long Live SLF4J!

Filed under: Java — Tags: , , , , , — Antony Stubbs @ 2:04 am

I support the complete abandonment of Commons Logging in favour of Simple Logging Facade 4 Java (SLF4J). Especially in libraries that use it – I think it’s amazing that Spring to link to it in their libraries!

For those of you that are blissfully un-aware of the hazards of the run time binding that commons logging uses and have been luckily enough not to have run into it yet – educate yourselves.

“Commons-logging promises to bridge to different logging APIs such as log4j, Avalon logkit and java.util.logging API. However, it’s dynamic discovery mechanism is the source of painful bugs.”

Apparently it’s his fault. Well mostly, as he admits:

“I’ll come right out and admit it: commons-logging, at least in its initial form, was my fault, though probably not mine alone.”

This guy deserves a medal. He freely hosts a great service for Maven users (yay! go Maven! (and Ivy and Gradle for that matter) ) that let’s you deal away with Commons Logging in your project easily.

The summary of the solution is basically:

<repositories>
    <repository>
        <id>Version99</id>
        <name>Version 99 Does Not Exist Maven repository</name>
        <layout>default</layout>
        <url>http://no-commons-logging.zapto.org/mvn2</url>
    </repository>
</repositories>
<dependencies>
    <!-- get empty jar instead of commons-logging -->
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>99.0-does-not-exist</version>
    </dependency>
</dependencies>

LogBack as mentioned in my previous post, along with SLF4J is a step into the recent present for logging technology (as opposed to living in pre-historic times of commons logging.

It’s really amaizing that something as seemingly simple as logging causes such a nightmare for so many people!

Update

Maven issue MNG-1977 will address this issue nicely by letting you globally exclude all commons-logging dependencies across all transitive dependencies in one statement.

Please so your neighbor-hood developer a favour, and vote for it 🙂

Advertisements

Create a free website or blog at WordPress.com.