Skip to content

Enhancement - Internal Logging Facade (decouple from java.util.logging) #829

@gissuebot

Description

@gissuebot

Original issue created by jmsignup on 2011-12-18 at 09:27 PM


Guava is an excellent library, and it prudently uses logging in places like Closeables.closeQuietly(Closeable) when an IOException is caught but not rethrown.

However, it is coupled to the java.util.logging logging implementation. This makes adapting guava logging to existing projects difficult, if those projects use a different log framework. Converting to slf4j has been discussed but rejected to limit non-JRE dependencies. The discussion suggests using slf4j's jul-to-slf4j bridge, but that comes with a 20% performance reduction, even with the latest logback implementation. As the jul-to-slf4j bridge documentation notes, the java.util.logging implementation is more difficult to work around because it is a part of the java namespace, which has certain restrictions on it.

Instead, enhance guava to intoduce an internal logging facade. This is in some ways similar to slf4j but without bringing in any new dependencies. By using an internal logging facade, guava because decoupled from java.util.logging, allowing pluggable logging implementations.

I suggest using a model similar to Netty's internal logging pattern, which exists for this very purpose. By having a logger and logger factory internal interface, you allow a simple extension to the library for using whatever logging implementation the user wants. By default, you can enable a java.util.logging implemetation (I suggest calling it something like JulLoggerFactory instead of Netty's JdkLoggerFactory, but that's a minor note). There are plenty of good logger interfaces available to model after. As I see it, you mainly need isXxxxLevelEnabled() and log.xxxx(String, Throwable) for the decided upon logging priority levels (like in log4j's Logger).

One other recommendation to Netty's implementation. I would prefer configuring the logger factory from a static call and also by specifying a class name in a system property. A system property ensures configurability at startup and is a pattern used throughout the JRE APIs, allowing for greater flexibility and adaptability to existing projects.

Minimizing non-JRE dependencies is a great goal for a common library like Guava but allow for plugging in other logging implementations for easier acceptance into more projects.

References:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions