Understanding Java Logging Frameworks: Relationships, Dependencies, and Integration

This article explains the evolution, relationships, and dependencies of Java logging libraries such as Log4j, JUL, JCL, SLF4J, and Logback, and provides practical guidance on configuring adapters, solving common conflicts, and unifying logging output across frameworks like Spring.

Top Architect
Top Architect
Top Architect
Understanding Java Logging Frameworks: Relationships, Dependencies, and Integration

Overview

The purpose of this article is to clarify the relationships among various Java logging libraries, explain how they work and depend on each other, and offer practical solutions for issues such as missing logs or jar conflicts, while showing how to unify logging output across different frameworks.

Log System

Typical Java projects may include many logging‑related jars such as commons-logging.jar, log4j.jar, slf4j-api.jar, and logback.jar; understanding their interactions is essential before configuring them.

Background / History

The evolution of Java logging can be summarized as follows:

log4j (by Ceki Gülcü) became the de‑facto standard and an Apache project.

Apache tried to merge log4j into the JDK, but Sun refused; JDK 1.4 introduced JUL ( java.util.logging ).

Because of API incompatibility, developers who wanted to switch from log4j to JUL had to modify code.

Apache created JCL (Jakarta Commons Logging) – a thin façade that provides a common API without an implementation.

Ceki Gülcü then developed SLF4J as a replacement for JCL and introduced Logback as a high‑performance implementation.

Apache later released log4j2 after learning from Logback.

Relationships / Dependencies

After the historical overview, the article details how these libraries depend on each other.

JCL

commons-logging

is no longer maintained; its usage has declined, and modern projects rarely rely on it.

SLF4J

SLF4J provides a façade that can bind to various logging implementations via adapters. The diagram (omitted) shows how SLF4J can work with Logback, Log4j, JUL, or even a no‑op implementation.

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 with no implementation: slf4j-api.jar +

slf4j-nop.jar

SLF4J Adapter Usage

To unify logging, you first identify which framework a module uses, then add the appropriate SLF4J adapter and remove unused implementations.

If a module uses JCL, add jcl-over-slf4j.jar.

If it uses Log4j, add log4j-over-slf4j.jar.

If it uses JUL, add jul-to-slf4j.jar.

Common Issues

Failed to load class org.slf4j.impl.StaticLoggerBinder

This error indicates that no logging implementation was found, often due to missing or incompatible jars.

Multiple bindings

When more than one SLF4J binding is present, SLF4J selects one arbitrarily, which can cause unexpected behavior.

Code Standards

【Mandatory】Do not use the native APIs of Log4j or Logback directly; instead, depend on SLF4J’s API to achieve a façade pattern for easier maintenance and uniform logging. import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger(Abc.class);

Conclusion

The article summarizes the relationships among Java logging components, explains how to resolve typical logging problems, and demonstrates how to configure a unified logging strategy using SLF4J and appropriate adapters.

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.

JavaBackend Developmentlogginglogbackslf4j
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

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.