Shouldn’t we Standardize a Java Logging API?
If you are interested in Java EE development and the roadmap, you might have read recently that theCloud 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 :
- JUL : the good old java.util.logging API that is included in our JDK. Bad luck, it is there and nobody uses it
- Log4j : widely used, Log4j hasn’t really been updated lately (update : the team is working on a 2.0 version)
- Commons Logging : How many more Apache logging frameworks do you want ?
- SLF4J : if you are not sure which logging API to use, well, use an abstraction (hum, abstraction, we love abstraction)
- Logback : the successor of Log4J (successor ? really ?)
- TinyLog : because all these frameworks are too big, we need to use a tiny one
- And many many many more Java logging frameworks
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:
1.
javax.ejb.level = debug
// EJB spec
2.
javax.persistence.level = debug
// JPA spec
3.
org.weld.level = debug
// CDI implementation (Weld)
4.
my.app.level = 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 ?
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)
No comments:
Post a Comment