Understanding Java Logging Frameworks and Their Relationships

This article explains the evolution, relationships, and dependencies of Java logging frameworks such as JCL, SLF4J, Log4j, Logback, and JUL, and provides practical guidance on configuring and unifying logging output across projects, including common pitfalls and adapter usage.

Java Captain
Java Captain
Java Captain
Understanding Java Logging Frameworks and Their Relationships

The purpose of this article is to clarify the relationships among various Java logging libraries, how they work together, and how to resolve common issues such as missing logs or jar conflicts, enabling consistent log output across different frameworks.

Historically, log4j became the de‑facto standard, Sun added JUL (java.util.logging) in JDK 1.4, and Apache introduced JCL (Jakarta Commons Logging) as a thin façade. Later, the author of log4j created slf4j to replace JCL, and also developed logback as a high‑performance implementation, followed by Apache’s log4j2.

Understanding these components’ dependencies is essential. commons-logging (JCL) is now unmaintained, while SLF4J provides adapters for many implementations, allowing you to plug in the desired backend.

Typical SLF4J adapter configurations include:

slf4j + logback: slf4j-api.jar + logback-classic.jar + logback-core.jar slf4j + log4j: slf4j-api.jar + slf4j-log4j12.jar + log4j.jar slf4j + JUL: slf4j-api.jar + slf4j-jdk14.jar slf4j without a concrete implementation: slf4j-api.jar + slf4j-nop.jar To make Spring (which uses JCL) log through SLF4J and Logback, simply add jcl-over-slf4j.jar to the classpath, removing other logging implementations.

Adaptation steps are straightforward: identify the logging framework used by each module, add the appropriate SLF4J bridge (e.g., jcl-over-slf4j.jar, log4j-over-slf4j.jar, jul-to-slf4j.jar), and eliminate unused logging jars.

Common problems include the “Failed to load class org.slf4j.impl.StaticLoggerBinder” error, which indicates a missing or incompatible logging implementation, and “Multiple bindings” warnings when more than one implementation is present.

Alibaba’s coding guidelines enforce using the SLF4J API instead of direct Log4j or Logback calls, promoting a unified logging approach:

import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger(Abc.class);

In summary, the article maps out the Java logging ecosystem, explains how to resolve typical logging issues, and demonstrates how to achieve consistent log output across a project by leveraging SLF4J adapters and best‑practice configurations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

logbacklog4jslf4jjcl
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.