Question

I have been using the Google Guava library and find it much more usable than Apache Commons for argument validation (i.e. checking preconditions, invariant object state, conveniently throwing the right Exception type on null, empty String, inlining null checks with assignments, Exception message formatting and specialised typing of nullable types). I have not looked at other features of the library but this was enough for me to switch.

Now the very natural question:

I am doing my logging using Apache Commons Logging, as I was doing for argument validation. Is there a similar "this goes to 11" of the framework from Google that I could switch to, with compound benefits? I don't mind either Log4j or Commons but Guava is so much better than Commons in the aspects I have studied...

I see Android has its logging framework, which I like, does Google offer one for basic Java too?


EDIT: Re-reading my question I realise it may somehow hint to a dogmatic preference for Google code, which I do not have, and an underlying assumption that anything that comes out of Google will be by definition "perfect". I do not hold these "positive preconceptions" at all, what I meant but failed to convey in writing, is that there may be some synergies in adopting a single provider for the two layers. There may be something that intelligently logs, for example, a Guava Optional object or associated object, saving time in constructing specific String.format()s. I was looking for a Google library to leverage these potential synergies not out of a priori preference. I did, in fact, first compare Guava to my old Commons-based way of argument checking before deciding to switch. All things considered, I do appreciate very much the code Google releases for free and I think I have learnt a lot from it and will continue to do so, given its very high quality. I never allowed this to become a cult, though.


References:

Was it helpful?

Solution

Commons Logging is best avoided. See http://articles.qos.ch/thinkAgain.html for a thorough analysis. Yes, it's very old (and yes, author has a vested interest) but it all applies. The linked 'Commons Logging was my fault' illustrates - there is really not much love for this library - anywhere.

Apparently, Google's preferred solution is java.util.logging. You will see this if you do Java programming on Google App Engine.

The best standard is slf4j over logback. There is no reason to avoid it I think. You will quite possibly be using slf4j already - if not directly then indirectly via other libraries on your classpath - it is the de facto modern standard.

OTHER TIPS

Not that I know of. I recommend using slf4j.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top