4

Why is JDK's Logging API considered so poor? What do we gain by using third party logging APIs such as Apache Log4j?

1
  • 5
    It would be a mistake to ignore history: log4j actually predates 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. Commented Mar 15, 2011 at 14:19

4 Answers 4

3

For most cases java.util.Logging is just fine. Most 3rd party logging packages were developed before the Standard API had any logging.

Sign up to request clarification or add additional context in comments.

Comments

2

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

"Should" seems rather definitive, no ?
Which doesn't really answer the question, it only modifies it: Why choose (the third party dependency) slf4j instead of (the built-in) JUL?
@Joachim Sauer , reason provided.
Sorry but it is not OK. Should choose slf4j if you are creating a library, so users can plug their chosen implementation into the facade, however, if it's an end-product it's usually more convenient to use a logging framework directly.
@z7sg, Let's say that using slf4j instead of a logging framework directly improves code's reusability, don't it? So it's wright way.
1

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

Isn't that very, very thin layer what slf4j tries to be?
Maybe, but it tries to be a very, very thin layer for ALL logging systems. :)
-2

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.

1 Comment

This is completely innacurate. Java Logging supports a Handler interface which allows you to log to practically anything. It also has 9 Levels at which to log at

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.