JDK Logging API
Why is JDK's Logging API considered so poor? What 开发者_开发百科do we gain by using third party logging APIs such as Apache Log4j?
For most cases java.util.Logging is just fine. Most 3rd party logging packages were developed before the Standard API had any logging.
Log4j was created before JDK's Logging API. Nowadays, you should prefer using slf4j for dealing with all java logging world in facade way.
I’m using a (very very thin) self-written layer on top of the JDK’s logging system because it is easy to use, easy to configure, and easy to extend. Even without this layer the JDK’s logging system is quite sufficient so that there is (in my opinion) no need for other logging APIs. Also, as it’s included in the JDK it should be considered a standard.
It's because the Logger class of the JDK isn't an interface. Therefore, you have no (very little) control about how the logging is done.
With commons-logging, log4j, slf4j you can choose how and where it should log the message. Whether this is into a file, into a database, redirect it to the application server logging, etc. With the JDK logging you can't. It's always to a file. And should you want another log level, you can't.
It does use varargs like slf4j, so you don't have to concatenate the String message beforehand. But the other disadvantages are too great.
精彩评论