質問

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 ?

役に立ちましたか?

解決

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.

他のヒント

Hibernate uses slf4j over apache commons logging.

Legacy code.

Inside of hibernate are full of commons logging usage. And simplest way to move from commons logging to desired logging library was adding slf4j layer. Now you can use one from popular logging library with Hibernate, which inside still use commons logging's interfaces. Also there were another reasone to move to slf4j.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top