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
This commit is contained in:
parent
e0100ea3f1
commit
3e15573628
|
@ -714,9 +714,9 @@ into logging calls to the SLF4J API, so if other libraries in your application u
|
||||||
API, then you have a single place to configure and manage logging.
|
API, then you have a single place to configure and manage logging.
|
||||||
|
|
||||||
A common choice might be to bridge Spring to SLF4J, and then provide explicit binding
|
A common choice might be to bridge Spring to SLF4J, and then provide explicit binding
|
||||||
from SLF4J to Log4J. You need to supply 4 dependencies (and exclude the existing
|
from SLF4J to Log4j. You need to supply several dependencies (and exclude the existing
|
||||||
`commons-logging`): the bridge, the SLF4J API, the binding to Log4J, and the Log4J
|
`commons-logging`): the bridge, the SLF4J implementation for Log4j, and the Log4j
|
||||||
implementation itself. In Maven you would do that like this
|
implementation itself. In Maven you would do that like this:
|
||||||
|
|
||||||
[source,xml,indent=0]
|
[source,xml,indent=0]
|
||||||
[subs="verbatim,quotes,attributes"]
|
[subs="verbatim,quotes,attributes"]
|
||||||
|
@ -739,19 +739,19 @@ implementation itself. In Maven you would do that like this
|
||||||
<version>1.7.22</version>
|
<version>1.7.22</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
<version>1.7.22</version>
|
<version>2.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>log4j-api</artifactId>
|
||||||
<version>1.7.22</version>
|
<version>2.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<version>1.2.17</version>
|
<version>2.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
----
|
----
|
||||||
|
@ -770,15 +770,18 @@ also need to exclude the slf4j-api dependency from other external dependencies (
|
||||||
Spring), because you only want one version of that API on the classpath.
|
Spring), because you only want one version of that API on the classpath.
|
||||||
|
|
||||||
|
|
||||||
[[overview-logging-log4j2]]
|
[[overview-logging-log4j]]
|
||||||
===== Using Log4j 2.x
|
===== Using Log4j
|
||||||
|
|
||||||
|
NOTE: Log4j 1.x is EOL and the following applies to Log4j 2
|
||||||
|
|
||||||
Many people use http://logging.apache.org/log4j[Log4j] as a logging framework for
|
Many people use http://logging.apache.org/log4j[Log4j] as a logging framework for
|
||||||
configuration and management purposes. It's efficient and well-established, and in fact
|
configuration and management purposes. It's efficient and well-established, and in fact
|
||||||
it's what we use at runtime when we build and test Spring. Spring also provides some
|
it's what we use at runtime when we build and test Spring. Spring also provides some
|
||||||
utilities for configuring and initializing Log4j, so it has an optional compile-time
|
utilities for configuring and initializing Log4j, so it has an optional compile-time
|
||||||
dependency on Log4j in some modules.
|
dependency on Log4j in some modules.
|
||||||
|
|
||||||
To use Log4j 2 with JCL, all you need to do is put Log4j 2 on the classpath and provide
|
To use Log4j with JCL, all you need to do is put Log4j on the classpath and provide
|
||||||
it with a configuration file (`log4j2.xml`, `log4j2.properties`, or other
|
it with a configuration file (`log4j2.xml`, `log4j2.properties`, or other
|
||||||
http://logging.apache.org/log4j/2.x/manual/configuration.html[supported configuration
|
http://logging.apache.org/log4j/2.x/manual/configuration.html[supported configuration
|
||||||
formats]). For Maven users, the minimal dependencies needed are:
|
formats]). For Maven users, the minimal dependencies needed are:
|
||||||
|
@ -787,7 +790,7 @@ formats]). For Maven users, the minimal dependencies needed are:
|
||||||
[source,xml,indent=0]
|
[source,xml,indent=0]
|
||||||
[subs="verbatim,quotes,attributes"]
|
[subs="verbatim,quotes,attributes"]
|
||||||
----
|
----
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
|
@ -798,7 +801,7 @@ formats]). For Maven users, the minimal dependencies needed are:
|
||||||
<artifactId>log4j-jcl</artifactId>
|
<artifactId>log4j-jcl</artifactId>
|
||||||
<version>2.7</version>
|
<version>2.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
----
|
----
|
||||||
|
|
||||||
If you also wish to use SLF4J, the following dependencies are also needed:
|
If you also wish to use SLF4J, the following dependencies are also needed:
|
||||||
|
@ -806,22 +809,22 @@ If you also wish to use SLF4J, the following dependencies are also needed:
|
||||||
[source,xml,indent=0]
|
[source,xml,indent=0]
|
||||||
[subs="verbatim,quotes,attributes"]
|
[subs="verbatim,quotes,attributes"]
|
||||||
----
|
----
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-slf4j-impl</artifactId>
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
<version>2.7</version>
|
<version>2.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
----
|
----
|
||||||
|
|
||||||
Here is an example log4j2.xml for logging to the console:
|
Here is an example `log4j2.xml` for logging to the console:
|
||||||
|
|
||||||
[source,xml,indent=0]
|
[source,xml,indent=0]
|
||||||
[subs="verbatim,quotes,attributes"]
|
[subs="verbatim,quotes,attributes"]
|
||||||
----
|
----
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Configuration status="WARN">
|
<Configuration status="WARN">
|
||||||
<Appenders>
|
<Appenders>
|
||||||
<Console name="Console" target="SYSTEM_OUT">
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||||
|
@ -833,47 +836,7 @@ Here is an example log4j2.xml for logging to the console:
|
||||||
<AppenderRef ref="Console"/>
|
<AppenderRef ref="Console"/>
|
||||||
</Root>
|
</Root>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
----
|
|
||||||
|
|
||||||
|
|
||||||
[[overview-logging-log4j]]
|
|
||||||
===== Using Log4J 1.x
|
|
||||||
To make http://logging.apache.org/log4j/1.2/[Log4j 1.x] work with the default JCL
|
|
||||||
dependency (`commons-logging`) all you need to do is put Log4j on the classpath, and
|
|
||||||
provide it with a configuration file (`log4j.properties` or `log4j.xml` in the root of
|
|
||||||
the classpath). So for Maven users this is your dependency declaration:
|
|
||||||
|
|
||||||
|
|
||||||
[source,xml,indent=0]
|
|
||||||
[subs="verbatim,quotes,attributes"]
|
|
||||||
----
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-core</artifactId>
|
|
||||||
<version>{spring-version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>1.2.17</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
----
|
|
||||||
|
|
||||||
And here's a sample log4j.properties for logging to the console:
|
|
||||||
|
|
||||||
[literal]
|
|
||||||
[subs="verbatim,quotes"]
|
|
||||||
----
|
|
||||||
log4j.rootCategory=INFO, stdout
|
|
||||||
|
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
|
|
||||||
|
|
||||||
log4j.category.org.springframework.beans.factory=DEBUG
|
|
||||||
----
|
----
|
||||||
|
|
||||||
[[overview-native-jcl]]
|
[[overview-native-jcl]]
|
||||||
|
@ -885,11 +848,11 @@ excluding `commons-logging` from your application is not enough in most situatio
|
||||||
|
|
||||||
To be clear about this: the problems reported are usually not with JCL per se, or even
|
To be clear about this: the problems reported are usually not with JCL per se, or even
|
||||||
with `commons-logging`: rather they are to do with binding `commons-logging` to another
|
with `commons-logging`: rather they are to do with binding `commons-logging` to another
|
||||||
framework (often Log4J). This can fail because `commons-logging` changed the way they do
|
framework (often Log4j). This can fail because `commons-logging` changed the way they do
|
||||||
the runtime discovery in between the older versions (1.0) found in some containers and
|
the runtime discovery in between the older versions (1.0) found in some containers and
|
||||||
the modern versions that most people use now (1.1). Spring does not use any unusual
|
the modern versions that most people use now (1.1). Spring does not use any unusual
|
||||||
parts of the JCL API, so nothing breaks there, but as soon as Spring or your application
|
parts of the JCL API, so nothing breaks there, but as soon as Spring or your application
|
||||||
tries to do any logging you can find that the bindings to Log4J are not working.
|
tries to do any logging you can find that the bindings to Log4j are not working.
|
||||||
|
|
||||||
In such cases with WAS the easiest thing to do is to invert the class loader hierarchy
|
In such cases with WAS the easiest thing to do is to invert the class loader hierarchy
|
||||||
(IBM calls it "parent last") so that the application controls the JCL dependency, not
|
(IBM calls it "parent last") so that the application controls the JCL dependency, not
|
||||||
|
|
Loading…
Reference in New Issue