Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the issue with the runtime discovery algorithm of Apache Commons Logging

Dave Syer (SpringSource) writes in his blog:

Unfortunately, the worst thing about commons-logging, and what has made it unpopular with new tools, is also the runtime discovery algorithm.

Why? What is the issue with its runtime discovery algorithm? Performance?

like image 895
Ta Sas Avatar asked Jul 11 '10 11:07

Ta Sas


People also ask

Is Apache Commons Logging affected by log4j?

3 Answers. Show activity on this post. Apache Commons Logging is an abstraction for the concrete implementation. It uses log4j, if present and configured.

What is org Apache Commons Logging?

Apache Commons Logging (previously known as Jakarta Commons Logging or JCL) is a Java-based logging utility and a programming model for logging and for other toolkits. It provides APIs, log implementations, and wrapper implementations over some other tools.

What is Apache Commons Logging in spring framework?

The Apache Commons Logging (JCL) provides a Log interface that is intended to be both light-weight and an independent abstraction of other logging toolkits.


1 Answers

Why? What is the issue with its runtime discovery algorithm? Performance?

No, it's not performance, it's classloader pain. JCL discovery process relies on classloader hacks to find the logging framework at runtime but this mechanism leads to numerous problems including unexpected behavior, hard to debug classloading problems resulting in increased complexity. This is nicely captured by Ceki (the author of Log4J, SLF4J and Logback) in Think again before adopting the commons-logging API (which also mentions memory leaks problems observed with JCL).

And this is why SLF4J, which uses static bindings, has been created.

Ceki being the author of SLF4J, you might think his articles are biased but, believe me, they are not and he is providing lots of references (evidences) to prove his point.

To sum up:

  • Yes, JCL is known to be broken, better stay away from it.
  • If you want to use a logging facade (not all projects need that), use SLF4J.
  • SLF4J provides a JCL-to-SLF4J bridge for frameworks still using JCL like Spring :(
  • I find Logback, Log4J's successor, to be a superior logging implementation.
  • Logback natively implements the SLF4J API. This means that if you are using Logback, you are actually using the SLF4J API.

See also

  • Commons Logging was my fault
  • Think again before adopting the commons-logging API
  • SLF4J Vs JCL / Dynamic Binding Vs Static Binding
like image 93
Pascal Thivent Avatar answered Sep 19 '22 11:09

Pascal Thivent