Ryan has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

What is Wrong with JDK Logger?

  • submit to reddit

I used to use log4j because it was most popular, but recently decided to try JDK logger in my current project. I like that it is built into the JDK so there are no .jar dependencies, version conflicts, etc. All I need it to do is write to a disk file using a format String I specify, rotate logs after x KB, and to keep only y archived files. I'm just as satisfied with it as I was with log4j.

A while ago I did some reading about the history of logging frameworks to try and understand the hostility many developers still have towards JDK logger. From what I can tell log4j was the first widely popular logging framework in Java. Later, its ideas and general API design were standardized in JDK 1.4. The names of some things were changed, but the concepts are the same. There were many developers who did not want to require "the new" Java 1.4 so they continued with log4j. Later the commons-logging wrapper was created to provide libraries and applications the ability to use either log4j or JDK logger depending on what is present in the environment. Even today with the pending release of Java 1.7 many developers use log4j or commons-logging instead of the built in JDK logger.

My question to you is what is wrong with the JDK logger? Why do some people say it was disaster? Why don't you use it? I am not trying to start a flamewar, I am genuinely interested. Is it because log4j comes with many more built-in appenders such as NTEventLogAppender, JMSAppender, and SMTPAppender? I figure the JDK logger has only basic core handlers/appenders for the same reason JSF comes only with basic HTML UI components.

From http://www.ryandelaplante.com


Published at DZone with permission of its author, Ryan Developer.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Luanne Misquitta replied on Thu, 2008/11/06 - 5:09am

I stopped using JDK logging quite a while back- if I remember correctly, I was very irritated with all the lock files- they caused some problems which I do not recall completely now...



Jay Bee replied on Wed, 2008/11/12 - 11:03am

Logging should not be this much work!

The bottom line for me is that logging should be Really Simple to use; Log4J is Really Simple and JUL isn't.

The very fact that this kind of conversation even exists illustrates something that is Horribly Wrong with the Java platform.

Wade Chandler replied on Thu, 2008/12/11 - 12:50pm in response to: Jay Bee

I guess it all depends on the eye of the beholder. I don't find JDK logger complex at all. Some do, and some don't. I have had issues with log4j configuration files in different classloaders and getting them to load correctly in the past, and as soon as the Java logging API came out I was using it and have not looked back for my own projects. I don't think it says there is anything wrong and certainly not *horribly wrong* with the Java platform.

I can find you all kinds of things that need to be better in about every thing I have ever used from .NET, to C++ std library, to Borland C++ components, to Java, Flash, Perl, Groovy, HTML...I'll spare you more, but that doesn't mean something is horribly wrong with any of them just that nothing is going to please everyone or hit every nail on the head. We are imperfect beings in an imperfect world. Show me perfect, and I'll probably tell you we must be dead because perfect doesn't exist.

Pedro Solorzano replied on Wed, 2009/03/04 - 12:26pm

If you are using GlassFish and JUL for example, you just have to go to the server admin console at Logging -> Levels, add a property for your root package and a Logging LEVEL (off course you can have a property even for a single class), and that's it. It takes the change without even restarting the server (and without the performance cost of the log4j Watch), no need for properties or web services. It is just plain easy and standard. I mean, Log4j was created on Apache, and the very author of it disagree with apache in many ways and then they have commons logging (said to be crap) and SLF4J which do the same thing and then every version, and library and... Why don't just use the standard of the language? IMHO.

Mathieu Carbou replied on Tue, 2011/01/11 - 11:19pm in response to: Nishant Kumar

You can use the JDK Logging API and still have separate log files for each webapp. See http://blog.mycila.com/2011/01/jdk-logging-per-webapp.html

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.