Skip to content

Commit 3e15573

Browse files
committed
Polish contribution
Since Log4J 1.x is EOL there is no need to have a dedicated section for it. Closes gh-1279 Issue: SPR-15170
1 parent e0100ea commit 3e15573

File tree

1 file changed

+54
-91
lines changed

1 file changed

+54
-91
lines changed

src/asciidoc/overview.adoc

Lines changed: 54 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ into logging calls to the SLF4J API, so if other libraries in your application u
714714
API, then you have a single place to configure and manage logging.
715715

716716
A common choice might be to bridge Spring to SLF4J, and then provide explicit binding
717-
from SLF4J to Log4J. You need to supply 4 dependencies (and exclude the existing
718-
`commons-logging`): the bridge, the SLF4J API, the binding to Log4J, and the Log4J
719-
implementation itself. In Maven you would do that like this
717+
from SLF4J to Log4j. You need to supply several dependencies (and exclude the existing
718+
`commons-logging`): the bridge, the SLF4J implementation for Log4j, and the Log4j
719+
implementation itself. In Maven you would do that like this:
720720

721721
[source,xml,indent=0]
722722
[subs="verbatim,quotes,attributes"]
@@ -739,19 +739,19 @@ implementation itself. In Maven you would do that like this
739739
<version>1.7.22</version>
740740
</dependency>
741741
<dependency>
742-
<groupId>org.slf4j</groupId>
743-
<artifactId>slf4j-api</artifactId>
744-
<version>1.7.22</version>
742+
<groupId>org.apache.logging.log4j</groupId>
743+
<artifactId>log4j-slf4j-impl</artifactId>
744+
<version>2.7</version>
745745
</dependency>
746746
<dependency>
747-
<groupId>org.slf4j</groupId>
748-
<artifactId>slf4j-log4j12</artifactId>
749-
<version>1.7.22</version>
747+
<groupId>org.apache.logging.log4j</groupId>
748+
<artifactId>log4j-api</artifactId>
749+
<version>2.7</version>
750750
</dependency>
751751
<dependency>
752-
<groupId>log4j</groupId>
753-
<artifactId>log4j</artifactId>
754-
<version>1.2.17</version>
752+
<groupId>org.apache.logging.log4j</groupId>
753+
<artifactId>log4j-core</artifactId>
754+
<version>2.7</version>
755755
</dependency>
756756
</dependencies>
757757
----
@@ -770,15 +770,18 @@ also need to exclude the slf4j-api dependency from other external dependencies (
770770
Spring), because you only want one version of that API on the classpath.
771771

772772

773-
[[overview-logging-log4j2]]
774-
===== Using Log4j 2.x
773+
[[overview-logging-log4j]]
774+
===== Using Log4j
775+
776+
NOTE: Log4j 1.x is EOL and the following applies to Log4j 2
777+
775778
Many people use http://logging.apache.org/log4j[Log4j] as a logging framework for
776779
configuration and management purposes. It's efficient and well-established, and in fact
777780
it's what we use at runtime when we build and test Spring. Spring also provides some
778781
utilities for configuring and initializing Log4j, so it has an optional compile-time
779782
dependency on Log4j in some modules.
780783

781-
To use Log4j 2 with JCL, all you need to do is put Log4j 2 on the classpath and provide
784+
To use Log4j with JCL, all you need to do is put Log4j on the classpath and provide
782785
it with a configuration file (`log4j2.xml`, `log4j2.properties`, or other
783786
http://logging.apache.org/log4j/2.x/manual/configuration.html[supported configuration
784787
formats]). For Maven users, the minimal dependencies needed are:
@@ -787,93 +790,53 @@ formats]). For Maven users, the minimal dependencies needed are:
787790
[source,xml,indent=0]
788791
[subs="verbatim,quotes,attributes"]
789792
----
790-
<dependencies>
791-
<dependency>
792-
<groupId>org.apache.logging.log4j</groupId>
793-
<artifactId>log4j-core</artifactId>
794-
<version>2.7</version>
795-
</dependency>
796-
<dependency>
797-
<groupId>org.apache.logging.log4j</groupId>
798-
<artifactId>log4j-jcl</artifactId>
799-
<version>2.7</version>
800-
</dependency>
801-
</dependencies>
793+
<dependencies>
794+
<dependency>
795+
<groupId>org.apache.logging.log4j</groupId>
796+
<artifactId>log4j-core</artifactId>
797+
<version>2.7</version>
798+
</dependency>
799+
<dependency>
800+
<groupId>org.apache.logging.log4j</groupId>
801+
<artifactId>log4j-jcl</artifactId>
802+
<version>2.7</version>
803+
</dependency>
804+
</dependencies>
802805
----
803806

804807
If you also wish to use SLF4J, the following dependencies are also needed:
805808

806-
[source,xml,indent=0]
807-
[subs="verbatim,quotes,attributes"]
808-
----
809-
<dependencies>
810-
<dependency>
811-
<groupId>org.apache.logging.log4j</groupId>
812-
<artifactId>log4j-slf4j-impl</artifactId>
813-
<version>2.7</version>
814-
</dependency>
815-
</dependencies>
816-
----
817-
818-
Here is an example log4j2.xml for logging to the console:
819-
820-
[source,xml,indent=0]
821-
[subs="verbatim,quotes,attributes"]
822-
----
823-
<?xml version="1.0" encoding="UTF-8"?>
824-
<Configuration status="WARN">
825-
<Appenders>
826-
<Console name="Console" target="SYSTEM_OUT">
827-
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
828-
</Console>
829-
</Appenders>
830-
<Loggers>
831-
<Logger name="org.springframework.beans.factory" level="DEBUG"/>
832-
<Root level="error">
833-
<AppenderRef ref="Console"/>
834-
</Root>
835-
</Loggers>
836-
</Configuration>
837-
----
838-
839-
840-
[[overview-logging-log4j]]
841-
===== Using Log4J 1.x
842-
To make http://logging.apache.org/log4j/1.2/[Log4j 1.x] work with the default JCL
843-
dependency (`commons-logging`) all you need to do is put Log4j on the classpath, and
844-
provide it with a configuration file (`log4j.properties` or `log4j.xml` in the root of
845-
the classpath). So for Maven users this is your dependency declaration:
846-
847-
848809
[source,xml,indent=0]
849810
[subs="verbatim,quotes,attributes"]
850811
----
851812
<dependencies>
852-
<dependency>
853-
<groupId>org.springframework</groupId>
854-
<artifactId>spring-core</artifactId>
855-
<version>{spring-version}</version>
856-
</dependency>
857-
<dependency>
858-
<groupId>log4j</groupId>
859-
<artifactId>log4j</artifactId>
860-
<version>1.2.17</version>
861-
</dependency>
813+
<dependency>
814+
<groupId>org.apache.logging.log4j</groupId>
815+
<artifactId>log4j-slf4j-impl</artifactId>
816+
<version>2.7</version>
817+
</dependency>
862818
</dependencies>
863819
----
864820

865-
And here's a sample log4j.properties for logging to the console:
821+
Here is an example `log4j2.xml` for logging to the console:
866822

867-
[literal]
868-
[subs="verbatim,quotes"]
823+
[source,xml,indent=0]
824+
[subs="verbatim,quotes,attributes"]
869825
----
870-
log4j.rootCategory=INFO, stdout
871-
872-
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
873-
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
874-
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
875-
876-
log4j.category.org.springframework.beans.factory=DEBUG
826+
<?xml version="1.0" encoding="UTF-8"?>
827+
<Configuration status="WARN">
828+
<Appenders>
829+
<Console name="Console" target="SYSTEM_OUT">
830+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
831+
</Console>
832+
</Appenders>
833+
<Loggers>
834+
<Logger name="org.springframework.beans.factory" level="DEBUG"/>
835+
<Root level="error">
836+
<AppenderRef ref="Console"/>
837+
</Root>
838+
</Loggers>
839+
</Configuration>
877840
----
878841

879842
[[overview-native-jcl]]
@@ -885,11 +848,11 @@ excluding `commons-logging` from your application is not enough in most situatio
885848

886849
To be clear about this: the problems reported are usually not with JCL per se, or even
887850
with `commons-logging`: rather they are to do with binding `commons-logging` to another
888-
framework (often Log4J). This can fail because `commons-logging` changed the way they do
851+
framework (often Log4j). This can fail because `commons-logging` changed the way they do
889852
the runtime discovery in between the older versions (1.0) found in some containers and
890853
the modern versions that most people use now (1.1). Spring does not use any unusual
891854
parts of the JCL API, so nothing breaks there, but as soon as Spring or your application
892-
tries to do any logging you can find that the bindings to Log4J are not working.
855+
tries to do any logging you can find that the bindings to Log4j are not working.
893856

894857
In such cases with WAS the easiest thing to do is to invert the class loader hierarchy
895858
(IBM calls it "parent last") so that the application controls the JCL dependency, not

0 commit comments

Comments
 (0)