Skip to content

Commit 4d86515

Browse files
committed
Overridable Commons Logging bridge in separate spring-jcl jar
Issue: SPR-14512
1 parent cf7dfc7 commit 4d86515

File tree

7 files changed

+48
-25
lines changed

7 files changed

+48
-25
lines changed

build.gradle

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ project("spring-build-src") {
301301
configurations.archives.artifacts.clear()
302302
}
303303

304+
project("spring-jcl") {
305+
description = "Spring Commons Logging Bridge"
306+
307+
dependencies {
308+
optional("org.apache.logging.log4j:log4j-api:${log4jVersion}")
309+
optional("org.slf4j:slf4j-api:${slf4jVersion}")
310+
}
311+
}
312+
304313
project("spring-core") {
305314
description = "Spring Core"
306315

@@ -366,8 +375,7 @@ project("spring-core") {
366375

367376
compile(files(cglibRepackJar))
368377
compile(files(objenesisRepackJar))
369-
optional("org.apache.logging.log4j:log4j-api:${log4jVersion}")
370-
optional("org.slf4j:slf4j-api:${slf4jVersion}")
378+
compile(project(":spring-jcl"))
371379
optional("net.sf.jopt-simple:jopt-simple:5.0.3")
372380
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
373381
optional("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ include "spring-context-indexer"
1010
include "spring-core"
1111
include "spring-expression"
1212
include "spring-instrument"
13+
include "spring-jcl"
1314
include "spring-jdbc"
1415
include "spring-jms"
1516
include "spring-messaging"

spring-core/src/main/java/org/apache/commons/logging/package-info.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Spring's variant of the
3+
* <a href="http://commons.apache.org/logging">Commons Logging API</a>:
4+
* with special support for Log4J 2, SLF4J and {@code java.util.logging}.
5+
*
6+
* <p>This is a custom bridge along the lines of {@code jcl-over-slf4j}.
7+
* You may exclude {@code spring-jcl} and switch to {@code jcl-over-slf4j}
8+
* instead if you prefer the hard-bound SLF4J bridge. However, Spring's own
9+
* bridge provides a better out-of-the-box experience when using Log4J 2
10+
* or {@code java.util.logging}, with no extra bridge jars necessary, and
11+
* also easier setup of SLF4J with Logback (no JCL exclude, no JCL bridge).
12+
*
13+
* <p>{@link org.apache.commons.logging.Log} is an unmodified repackaging.
14+
* However, {@link org.apache.commons.logging.LogFactory} is a very different
15+
* implementation which is minimized and optimized for Spring's purposes,
16+
* detecting Log4J 2.x and SLF4J 1.7 in the framework classpath and falling
17+
* back to {@code java.util.logging}. If you run into any issues with this
18+
* implementation, consider excluding {@code spring-jcl} and switching to the
19+
* standard {@code commons-logging} artifact or to {@code jcl-over-slf4j}.
20+
*
21+
* <p>Note that this Commons Logging bridge is only meant to be used for
22+
* framework logging purposes, both in the core framework and in extensions.
23+
* For applications, prefer direct use of Log4J/SLF4J or {@code java.util.logging}.
24+
*/
25+
package org.apache.commons.logging;

src/docs/asciidoc/overview.adoc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ Although Spring provides integration and support for a huge range of enterprise
395395
other external tools, it intentionally keeps its mandatory dependencies to an absolute
396396
minimum: you shouldn't have to locate and download (even automatically) a large number
397397
of jar libraries in order to use Spring for simple use cases. For basic dependency
398-
injection there is only one mandatory external dependency, and that is for logging (see
399-
below for a more detailed description of logging options).
398+
injection there is only one mandatory external dependency, and that is for logging
399+
(see below for a more detailed description of logging options).
400400

401401
Next we outline the basic steps needed to configure an application that depends on
402402
Spring, first with Maven and then with Gradle and finally using Ivy. In all cases, if
@@ -597,11 +597,12 @@ http://repo.spring.io/snapshot/org/springframework/spring[snapshots].
597597
==== Logging
598598
Spring's logging setup has been revised for Spring 5: It is still based on the Apache
599599
Commons Logging API, also known as Jakarta Commons Logging (JCL). However, `spring-core`
600-
includes an embedded variant of Commons Logging now, with a Spring-specific `LogFactory`
601-
which automatically bridges to https://logging.apache.org/log4j/2.x/[Log4j 2],
602-
http://www.slf4j.org[SLF4J], or the JDK's own `java.util.logging` (JUL). This
603-
implementation acts like the JCL-over-SLF4J bridge but with a range of dynamically
604-
detected providers, analogous to JBoss Logging's common targets (as used by Hibernate).
600+
refers to a custom Commons Logging bridge in the `spring-jcl` module now, with a
601+
Spring-specific `LogFactory` implementation which automatically bridges to
602+
https://logging.apache.org/log4j/2.x/[Log4j 2], http://www.slf4j.org[SLF4J], or the
603+
JDK's own `java.util.logging` (JUL). This implementation acts like the JCL-over-SLF4J
604+
bridge but with a range of dynamically detected providers, analogous to JBoss Logging's
605+
common targets (as supported by e.g. Hibernate and Undertow).
605606

606607
As a benefit, there is no need for external bridges like JCL-over-SLF4J anymore,
607608
and correspondingly no need for a manual exclude of the standard Commons Logging jar
@@ -630,6 +631,10 @@ up since Spring's bridge does not support custom `commons-logging.properties' se
630631
For any other log provider, please set up a corresponding SLF4J or JUL bridge (which
631632
you are very likely going to need for other libraries such as Hibernate anyway).
632633
Note that Log4j 1.x has reached its end-of-life; please migrate to Log4j 2.x.
634+
635+
If you run into any remaining issues with Spring's Commons Logging implementation,
636+
consider excluding `spring-jcl` and switching to the standard `commons-logging`
637+
artifact (supporting `commons-logging.properties' setup) or to `jcl-over-slf4j`.
633638
====
634639

635640
[[overview-logging-log4j]]

0 commit comments

Comments
 (0)