From 4d86515fa55dbc4ff9ff434effc3a73c1a04c2fa Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 3 May 2017 20:29:05 +0200 Subject: [PATCH] Overridable Commons Logging bridge in separate spring-jcl jar Issue: SPR-14512 --- build.gradle | 12 +++++++-- settings.gradle | 1 + .../apache/commons/logging/package-info.java | 16 ------------ .../java/org/apache/commons/logging/Log.java | 0 .../apache/commons/logging/LogFactory.java | 0 .../apache/commons/logging/package-info.java | 25 +++++++++++++++++++ src/docs/asciidoc/overview.adoc | 19 ++++++++------ 7 files changed, 48 insertions(+), 25 deletions(-) delete mode 100644 spring-core/src/main/java/org/apache/commons/logging/package-info.java rename {spring-core => spring-jcl}/src/main/java/org/apache/commons/logging/Log.java (100%) rename {spring-core => spring-jcl}/src/main/java/org/apache/commons/logging/LogFactory.java (100%) create mode 100644 spring-jcl/src/main/java/org/apache/commons/logging/package-info.java diff --git a/build.gradle b/build.gradle index a85df819f2b..33cb600eb37 100644 --- a/build.gradle +++ b/build.gradle @@ -301,6 +301,15 @@ project("spring-build-src") { configurations.archives.artifacts.clear() } +project("spring-jcl") { + description = "Spring Commons Logging Bridge" + + dependencies { + optional("org.apache.logging.log4j:log4j-api:${log4jVersion}") + optional("org.slf4j:slf4j-api:${slf4jVersion}") + } +} + project("spring-core") { description = "Spring Core" @@ -366,8 +375,7 @@ project("spring-core") { compile(files(cglibRepackJar)) compile(files(objenesisRepackJar)) - optional("org.apache.logging.log4j:log4j-api:${log4jVersion}") - optional("org.slf4j:slf4j-api:${slf4jVersion}") + compile(project(":spring-jcl")) optional("net.sf.jopt-simple:jopt-simple:5.0.3") optional("org.aspectj:aspectjweaver:${aspectjVersion}") optional("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}") diff --git a/settings.gradle b/settings.gradle index d62c833cc60..ee90fc5c810 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,6 +10,7 @@ include "spring-context-indexer" include "spring-core" include "spring-expression" include "spring-instrument" +include "spring-jcl" include "spring-jdbc" include "spring-jms" include "spring-messaging" diff --git a/spring-core/src/main/java/org/apache/commons/logging/package-info.java b/spring-core/src/main/java/org/apache/commons/logging/package-info.java deleted file mode 100644 index 8704c7664ce..00000000000 --- a/spring-core/src/main/java/org/apache/commons/logging/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Spring's variant of the - * Commons Logging API - * (for internal use only). - * - *

{@link org.apache.commons.logging.Log} is an unmodified repackaging. - * However, {@link org.apache.commons.logging.LogFactory} is a very different - * implementation which is minimized and optimized for Spring's purposes, - * detecting Log4J 2.x and SLF4J 1.7 in the framework classpath and falling - * back to {@code java.util.logging}. - * - *

Note that this Commons Logging variant is only meant to be used for - * framework logging purposes, both in the core framework and in extensions. - * For applications, prefer direct use of Log4J or SLF4J or {@code java.util.logging}. - */ -package org.apache.commons.logging; diff --git a/spring-core/src/main/java/org/apache/commons/logging/Log.java b/spring-jcl/src/main/java/org/apache/commons/logging/Log.java similarity index 100% rename from spring-core/src/main/java/org/apache/commons/logging/Log.java rename to spring-jcl/src/main/java/org/apache/commons/logging/Log.java diff --git a/spring-core/src/main/java/org/apache/commons/logging/LogFactory.java b/spring-jcl/src/main/java/org/apache/commons/logging/LogFactory.java similarity index 100% rename from spring-core/src/main/java/org/apache/commons/logging/LogFactory.java rename to spring-jcl/src/main/java/org/apache/commons/logging/LogFactory.java diff --git a/spring-jcl/src/main/java/org/apache/commons/logging/package-info.java b/spring-jcl/src/main/java/org/apache/commons/logging/package-info.java new file mode 100644 index 00000000000..bd070b69e44 --- /dev/null +++ b/spring-jcl/src/main/java/org/apache/commons/logging/package-info.java @@ -0,0 +1,25 @@ +/** + * Spring's variant of the + * Commons Logging API: + * with special support for Log4J 2, SLF4J and {@code java.util.logging}. + * + *

This is a custom bridge along the lines of {@code jcl-over-slf4j}. + * You may exclude {@code spring-jcl} and switch to {@code jcl-over-slf4j} + * instead if you prefer the hard-bound SLF4J bridge. However, Spring's own + * bridge provides a better out-of-the-box experience when using Log4J 2 + * or {@code java.util.logging}, with no extra bridge jars necessary, and + * also easier setup of SLF4J with Logback (no JCL exclude, no JCL bridge). + * + *

{@link org.apache.commons.logging.Log} is an unmodified repackaging. + * However, {@link org.apache.commons.logging.LogFactory} is a very different + * implementation which is minimized and optimized for Spring's purposes, + * detecting Log4J 2.x and SLF4J 1.7 in the framework classpath and falling + * back to {@code java.util.logging}. If you run into any issues with this + * implementation, consider excluding {@code spring-jcl} and switching to the + * standard {@code commons-logging} artifact or to {@code jcl-over-slf4j}. + * + *

Note that this Commons Logging bridge is only meant to be used for + * framework logging purposes, both in the core framework and in extensions. + * For applications, prefer direct use of Log4J/SLF4J or {@code java.util.logging}. + */ +package org.apache.commons.logging; diff --git a/src/docs/asciidoc/overview.adoc b/src/docs/asciidoc/overview.adoc index e66fb4864d6..ae911f1c2ca 100644 --- a/src/docs/asciidoc/overview.adoc +++ b/src/docs/asciidoc/overview.adoc @@ -395,8 +395,8 @@ Although Spring provides integration and support for a huge range of enterprise other external tools, it intentionally keeps its mandatory dependencies to an absolute minimum: you shouldn't have to locate and download (even automatically) a large number of jar libraries in order to use Spring for simple use cases. For basic dependency -injection there is only one mandatory external dependency, and that is for logging (see -below for a more detailed description of logging options). +injection there is only one mandatory external dependency, and that is for logging +(see below for a more detailed description of logging options). Next we outline the basic steps needed to configure an application that depends on 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]. ==== Logging Spring's logging setup has been revised for Spring 5: It is still based on the Apache Commons Logging API, also known as Jakarta Commons Logging (JCL). However, `spring-core` -includes an embedded variant of Commons Logging now, with a Spring-specific `LogFactory` -which automatically bridges to https://logging.apache.org/log4j/2.x/[Log4j 2], -http://www.slf4j.org[SLF4J], or the JDK's own `java.util.logging` (JUL). This -implementation acts like the JCL-over-SLF4J bridge but with a range of dynamically -detected providers, analogous to JBoss Logging's common targets (as used by Hibernate). +refers to a custom Commons Logging bridge in the `spring-jcl` module now, with a +Spring-specific `LogFactory` implementation which automatically bridges to +https://logging.apache.org/log4j/2.x/[Log4j 2], http://www.slf4j.org[SLF4J], or the +JDK's own `java.util.logging` (JUL). This implementation acts like the JCL-over-SLF4J +bridge but with a range of dynamically detected providers, analogous to JBoss Logging's +common targets (as supported by e.g. Hibernate and Undertow). As a benefit, there is no need for external bridges like JCL-over-SLF4J anymore, 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 For any other log provider, please set up a corresponding SLF4J or JUL bridge (which you are very likely going to need for other libraries such as Hibernate anyway). Note that Log4j 1.x has reached its end-of-life; please migrate to Log4j 2.x. + +If you run into any remaining issues with Spring's Commons Logging implementation, +consider excluding `spring-jcl` and switching to the standard `commons-logging` +artifact (supporting `commons-logging.properties' setup) or to `jcl-over-slf4j`. ==== [[overview-logging-log4j]]