DevOps Zone is brought to you in partnership with:

Antonio Goncalves is a senior software architect living in Paris. Initially focused on Java development since the late 1990s, his career has taken him to different countries and companies where he works now as a Java EE consultant in software architecture. As a former BEA consultant he has a great expertise in application servers such as Weblogic, JBoss and, of course, GlassFish. He is particularly fond of Open Source and is a member of the OOSGTP (Open Source Get Together Paris). He is also the co-creator of the Paris Java User Group and talks on Les Cast Codeurs podcast. Antonio wrote a first book in French on Java EE 5 back in 2007. Since then he has join the JCP and is an Expert Member of various JSRs (Java EE 6, JPA 2.0 and EJB 3.1). He then published a second book for Apress: Beginning Java EE 6 Platform with GlassFish 3. For the last years Antonio has been talking at international conferences mainly about Java EE, including JavaOne, The Server Side Symposium, Devoxx, Jazoon… He has also written numerous technical papers and articles for IT Web sites (DevX, JaxEnter) or IT magazines (Programmez, Linux Magazine). Antonio is a DZone MVB and is not an employee of DZone and has posted 33 posts at DZone. You can read more from them at their website. View Full User Profile

Shouldn’t we Standardize a Java Logging API?

  • submit to reddit

I need you for Logging API Spec LeadIf you are interested in Java EE development and the roadmap, you might have read recently that the Cloud feature in Java EE 7 has been delayed. As I’ve already expressed in the Java EE 7 expert group mailing list, I’m happy about this news because I feel standardizing cloud in EE 7 was way too early. But I’m also sad. Sad because we’ve spent a lot of time discussing Cloud, PaaS, multi-tenancy… and not concentrating on other topics. And one topic that I have in mind is logging!  Shouldn’t we standardize a Logging API ?

A few months ago I was struggling (again) with logging configuration in JBoss 7.x. I was so depressed that I wrote to the Java EE 7 expert group : Logs. Should we finally do something ? (you should read it, there are valuable opinions expressed by the members). As a developer I’ve used all the possible logging Java frameworks for the last 12 years and I still struggle with logging in 2012. How many logging frameworks do we have ? Look at the list :

I’m not a log expert and I’m sure all these frameworks exist for good reasons (I’m trying to be politically correct here), but for god sake, we just need to write logs. I don’t want to do a benchmark of all the logging APIs to make up my mind. I don’t want to have to relearn a new logging framework each time a new version of my application server is out (yes, JBoss 7 uses its own JBoss Logging API). To be honest, instead of all saying “using System.out.println is bad” we should have encouraged it and let Java SE redirect the messages to files (using external configuration). This way our code would be full of System.out.println("message") or System.out.println(WARNING, "message") and we would have avoided all the logging frameworks. Anyway, this is the situation we’re in.

Let’s standardize a logging API

Standardizing too soon is bad… but we’ve been doing logs for more than a decade now. We have a big expertise in logging, we could even take some ideas of other languages. So it’s time to standardize logging. Let’s not do the same mistake as JUL  and only standardize an API. Then, we could let all the known frameworks to implement it and fight about better performances or functionalities. Today, logging portability is a nightmare, enough. With a standard API we could also have some tooling and descent log viewers coming on board.

Integrate this logging API in Java EE (and other specs)

If all the Java EE specs (EJB, JPA, JAX-RS, CDI…) use this standard API and impose it to the implementations, we could then easily change the level of logs in a standard way on our applications by using a simple package naming convetion:

javax.ejb.level = debug         // EJB spec
javax.persistence.level = debug // JPA spec
org.weld.level = debug          // CDI implementation (Weld) = debug            // My application

And who knows, when modularization arrives we could get rid of java.util.logging and have a new javax.logging module in Java SE (and choose the implementation).

Think to the future

If we had a Logging API 1.0 specification, then, when multi-tenancy comes along, we could have a Logging API 1.1 which handles it (wouldn’t it be nice to have multi-tenant logs with no effort ?). Another idea would be to play with staging. JSF 2.0 introduced staging and it might be spread all over Java EE. If that’s the case, we could simply use default logging : DEBUG for development, WARNING for production… That would simplify configuration.

Do you feel like being a spec lead ?

No, it’s not because I write this blog post that I want to be a spec lead. I’m not the right person, I’ve never implemented a logging framework, I’m just a user of theses APIs. So if you feel you know the topic well, if you know people who could help you by being part of your expert group (if you want, I could even join this expert group), then do it. Entering the JCP is not a piece of cake, you need to do a bit of administration to have your JSR approved, but it’s doable.  You would need a bit of time, but it’s doable. Even if you start now I’m not sure there will be enough time to take the Java EE 7 train, but the JCP has some examples of quick JSRs.

So, who wants to be a Logging API Spec Lead ? Do you think it’s a good idea to standardize a Logging API ?

Published at DZone with permission of Antonio Goncalves, author and DZone MVB. (source)

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


John J. Franey replied on Fri, 2012/09/07 - 8:57am

You are looking for an API, mention one, and fail to recognize it as an API.  It is right under your nose. 


  • If log4j, jul, logback are logging frameworks, then slf4j and commons-logging are not.  slf4j and commons-logging are facades that delegate to the log4j and jul.  Logback is an implementation of the slf4j api.   slf4j differs from commons-logging architecturally by the mechanism the facade uses to determine which framework to delegate.   With slf4j, deployer (person who deploys) explicitly specifies the delegation (with a binding jar file in deployment package or container).    Commons-logging delegates to the framework it discovers on the runtime classpath.
  • The attempt to standardize is the root cause of the diversity.  Logging framework WAS standardized on JUL.  This standard dejure was ignored by many because log4j was the standard defacto at the time.  Out popped commons-logging to resolve, but the dynamic discovery is problematic in a app server runtime.  So, static binding is offerered now in slf4j.  You are opening old wounds and history repeats (e.g. OSGI vs Jigsaw).
  • Many open source libraries and systems are converging on slf4j as an API.   It is a defacto standard.  No need for a standardization committee.  An attempt to standardize on an API will fracture things all over again.
  • The problem you describe does not exist.  I use this defacto api (slf4j) and the framework that suits the runtime requirements.  I use logback during testing.  My apps will run with either log4j or jul frameworks.


 Let it lie.

Michele Mauro replied on Fri, 2012/09/07 - 9:51am

Just one url:

The other comment says it all.

Mirkus Mirkelinos replied on Fri, 2012/09/07 - 9:51am in response to: John J. Franey

+1 for John's comment. That's my point of view too.

Jonathan Fisher replied on Fri, 2012/09/07 - 11:18am

The community is slowing standardizing SLF4J IMHO. It's the API the author is looking for.

SLF4J is nothing but a vanilla API and set of interfaces. This author assumes it's an implementation. It's literally an API, nothing else.

Logback implements those interfaces. So it is _no way_ a successor, it's an *implementation*. SLF4J is useless without implementations, and Logback is useless without an API. There are 5-6 implementations of SLF4J, which is cool. I like choice :)

This is awesome for API designers/library inventors. Then can write their code with contextual log statements, and the consumer of their library can choose to ignore or add an implementation of those log statements later. 

Honestly, if it isn't too much trouble, I'd ask the author to publish a correction; I'd hate for someone to make an assumption that Logback is a successor.

Nicolas Seyvet replied on Fri, 2012/09/07 - 11:20am in response to: Jonathan Fisher

I get the point of the author.  Even if SLF4J is the de-facto standard it is not recognized as such because it is not a JSR API.  It would simple to say: "OK, SLF4J is the standard. It is used as such -> JSR defined".  End of conversation about which logging FW to use when developping SW.


John J. Franey replied on Fri, 2012/09/07 - 11:47am in response to: Nicolas Seyvet

 End of conversation about which logging FW to use when developping SW.
   The JSR for a logging api was released in 2001.  It did not end the conversation.

Gregory Smith replied on Fri, 2012/09/07 - 2:24pm

My preference would be to have a "log" method on the Object class. Every object potentially needs logging - most will use logging at one time or another. 

It could work the same way that JUL and log4j do, but natively as part of the Object class. Configuring the logger and appender could be done declaritively or programmatically with sane defaults just like log4j and JUL. Additional "trc", "dbg", "cfg", "inf", "wrn", "err", and "ftl" methods could be available as shortcuts for logging at particular log levels.

The JVM could be smart enough to recognise the calls to log methods and skip them entirely if they are below the log level (avoiding unneeded method calls).

Of course, it is a little late to be adding it to Java now as it would likely cause problems with existing code.  Maybe a new language like Kotlin could add this feature. 

Nicolas Seyvet replied on Fri, 2012/09/07 - 4:08pm in response to: John J. Franey


Really? Ouppss... Never heard of it 

Thibault Delor replied on Sat, 2012/09/08 - 7:12am

Hi Antonio,

The JSR already exists : JSR-47. Making an other JSR wouldn't have any sense.

The problem is not to have a JSR but how to make everyone use this spec... 

Dapeng Liu replied on Mon, 2012/09/10 - 2:31am

what's wrong with JUL? i am quite happy with jul from glassfish ... 

Joern Haferstroh replied on Tue, 2012/09/11 - 4:10am

What I would like to see regarding JEE logging, is the possibility to configure "logging targets" in the application server console and use them in my application via JNDI lookup or injection, just the way like data sources for JDBC. This way the log file path, size and rolling options can be configured easily outside the application.

Comment viewing options

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