Why is JDK's Logging API considered so poor? What do we gain by using third party logging APIs such as Apache Log4j?
4 Answers
Log4j was created before JDK's Logging API. Nowadays, you should prefer using slf4j for dealing with all java logging world in facade way.
5 Comments
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.
2 Comments
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.
java.util.logging(which was only added in 1.4). So it had a 3 or so year head start to be established as the standard. Point being, it's not like log4j got really popular by being an alternative to JUL.