Search code examples
javahibernateloggingslf4japache-commons-logging

Hibernate uses apache commons logging and slf4j - why are 2 logging abstraction layers needed?


I am not so experienced in the java logging libraries world. I started using hibernate and then saw I needed to include apache commons logging library and sl4j library. The actual logging library is log4j - so I included that library too.

After reading about apache commons logging and sl4j libs, I understand that they both represent an abstraction layer for logging with another library (log4j in my case).

Why are 2 abstraction levels needed ?


Solution

  • In a perfect world, these multiple logging API are not needed, but unfortunately, there is no clear standard, so different libraries (and Hibernate is a big project with many dependencies and sub-projects) use different logging API, and as a user, you have to provide all of them.

    The quasi-standard was Log4J, until Sun decided it needed to include its own version (java.util.logging) into the JDK. That made it a two-horse race, and Commons Logging was designed to provide a unified interface to both (and any others). Unfortunately, Commons Logging had some short-comings, too, so the current favourite is SLF4J. SLF4J tries to help with cleaning up the mess by providing bridges to all other API, too.