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 :)

About these ads

3 Comments »

  1. Hello Tony,

    Thank you for your support of the SLF4J project. I’d like to link to this blog entry from slf4j.org. However, since its title starts with “Death to Commons Logging”, I can’t. The developers who work on commons-logging personally are cool people and deserve a bit more respect. So, how about changing the title to “Long live SLF4J” without the death part?

    Comment by ceki — August 17, 2008 @ 6:02 am

  2. That’s better!
    For everyone’s benefit;
    I don’t intend to offend, but I do tend to agree with Linus, in that strong opinions are needed in a sea of apathy and ignorance.

    Comment by Antony Stubbs — August 21, 2008 @ 7:21 pm

  3. [...] Not a fan of commons-logging. [...]

    Pingback by The Cave » Blog Archive » slf4j — November 21, 2008 @ 5:25 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

The Shocking Blue Green Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 686 other followers

%d bloggers like this: