Discussion:
Apache commons-logging bridge for log4j2
Asma Zinneera Jabir
2017-07-05 08:30:22 UTC
Permalink
I am trying to set up log4j2 for Apache Commons Logging using the
*commons-logging.properties* file in an OSGi environment. For Log4j 1 I
could use org.apache.commons.logging.Log=org.apache.commons.logging.impl.
Log4JLogger which maps to version Log4j 1.2. I couldn't find out the
implementation for log4J2. The version I am using is 2.8.2.

There is a central logging component which is referred by other components
and this component bundles other needed loggers (e.g. commons-logging,
log4j/log4j2) added as dependencies.

The Log4J2 documentation for Log4J Commons Logging Bridge
<https://logging.apache.org/log4j/log4j-2.3/log4j-jcl/index.html> specifies
that by just *adding the bridge jar along with the other Log4j 2 jars and
the Commons Logging jar, all logging done using the Commons Logging API
will be routed to Log4*. I tried this by adding

- log4j-api
- log4j-core
- log4j-jcl
- commons-logging

dependencies in the *pom.xml* of the central logging component and bundled
with it without (and with just to check) using the
*commons-logging.properties* but didn't work that way. How can I implement
this with or without the commons-logging.properties?

I debugged the commons-logging source code and found in LogFactoryImpl.java it
looks for a logging implementation (L843
<https://github.com/apache/commons-logging/blob/LOGGING_1_2/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java#L843>)
from a list (L162
<https://github.com/apache/commons-logging/blob/LOGGING_1_2/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java#L162>).
Here since the Log4JLogger does not support Log4J2 it then sets to the next
in line, that is JDK14Logger. Since the Log4J2 documentaiton says adding
the bridge simply maps the logs from JCL to Log4J2, what role does the
bridging api play here? I noticed the LogFactoryImpl.java and Log4JLog.java in
it but how does commons-logging refer to these which are in a different
package?

stackoverflow question: Apache commons-logging bridge for log4j2
<https://stackoverflow.com/questions/44839779/apache-commons-logging-bridge-for-log4j2>
Matt Sicker
2017-07-05 17:27:23 UTC
Permalink
It's loaded via the ServiceLoader interface:

https://github.com/apache/logging-log4j2/blob/master/log4j-jcl/src/main/resources/META-INF/services/org.apache.commons.logging.LogFactory
Post by Asma Zinneera Jabir
I am trying to set up log4j2 for Apache Commons Logging using the
*commons-logging.properties* file in an OSGi environment. For Log4j 1 I
could use org.apache.commons.logging.Log=org.apache.commons.logging.impl.
Log4JLogger which maps to version Log4j 1.2. I couldn't find out the
implementation for log4J2. The version I am using is 2.8.2.
There is a central logging component which is referred by other components
and this component bundles other needed loggers (e.g. commons-logging,
log4j/log4j2) added as dependencies.
The Log4J2 documentation for Log4J Commons Logging Bridge
<https://logging.apache.org/log4j/log4j-2.3/log4j-jcl/index.html> specifies
that by just *adding the bridge jar along with the other Log4j 2 jars and
the Commons Logging jar, all logging done using the Commons Logging API
will be routed to Log4*. I tried this by adding
- log4j-api
- log4j-core
- log4j-jcl
- commons-logging
dependencies in the *pom.xml* of the central logging component and bundled
with it without (and with just to check) using the
*commons-logging.properties* but didn't work that way. How can I implement
this with or without the commons-logging.properties?
I debugged the commons-logging source code and found in
LogFactoryImpl.java it
looks for a logging implementation (L843
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java#L843
)
from a list (L162
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java#L162
).
Here since the Log4JLogger does not support Log4J2 it then sets to the next
in line, that is JDK14Logger. Since the Log4J2 documentaiton says adding
the bridge simply maps the logs from JCL to Log4J2, what role does the
bridging api play here? I noticed the LogFactoryImpl.java and
Log4JLog.java in
it but how does commons-logging refer to these which are in a different
package?
stackoverflow question: Apache commons-logging bridge for log4j2
<https://stackoverflow.com/questions/44839779/apache-
commons-logging-bridge-for-log4j2>
--
Matt Sicker <***@gmail.com>
Ralph Goers
2017-07-05 17:29:33 UTC
Permalink
The ServiceLoader needs special handling to work in OSGi. See http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html <http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html>

Ralph
Post by Matt Sicker
https://github.com/apache/logging-log4j2/blob/master/log4j-jcl/src/main/resources/META-INF/services/org.apache.commons.logging.LogFactory
Post by Asma Zinneera Jabir
I am trying to set up log4j2 for Apache Commons Logging using the
*commons-logging.properties* file in an OSGi environment. For Log4j 1 I
could use org.apache.commons.logging.Log=org.apache.commons.logging.impl.
Log4JLogger which maps to version Log4j 1.2. I couldn't find out the
implementation for log4J2. The version I am using is 2.8.2.
There is a central logging component which is referred by other components
and this component bundles other needed loggers (e.g. commons-logging,
log4j/log4j2) added as dependencies.
The Log4J2 documentation for Log4J Commons Logging Bridge
<https://logging.apache.org/log4j/log4j-2.3/log4j-jcl/index.html> specifies
that by just *adding the bridge jar along with the other Log4j 2 jars and
the Commons Logging jar, all logging done using the Commons Logging API
will be routed to Log4*. I tried this by adding
- log4j-api
- log4j-core
- log4j-jcl
- commons-logging
dependencies in the *pom.xml* of the central logging component and bundled
with it without (and with just to check) using the
*commons-logging.properties* but didn't work that way. How can I implement
this with or without the commons-logging.properties?
I debugged the commons-logging source code and found in
LogFactoryImpl.java it
looks for a logging implementation (L843
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java#L843
)
from a list (L162
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java#L162
).
Here since the Log4JLogger does not support Log4J2 it then sets to the next
in line, that is JDK14Logger. Since the Log4J2 documentaiton says adding
the bridge simply maps the logs from JCL to Log4J2, what role does the
bridging api play here? I noticed the LogFactoryImpl.java and
Log4JLog.java in
it but how does commons-logging refer to these which are in a different
package?
stackoverflow question: Apache commons-logging bridge for log4j2
<https://stackoverflow.com/questions/44839779/apache-
commons-logging-bridge-for-log4j2>
--
Asma Zinneera Jabir
2017-07-07 05:49:06 UTC
Permalink
I went through the ServiceLoader usages and asking from what I understand.
Does this mean that on top of adding the bridge dependency in the central
logging component I also have to use the ServiceLoader in each and every
file importing commons-logging to find the LogFactoryImpl in the bridge to
overrite it?
Post by Ralph Goers
The ServiceLoader needs special handling to work in OSGi. See
http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html <
http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html>
Ralph
Post by Matt Sicker
https://github.com/apache/logging-log4j2/blob/master/
log4j-jcl/src/main/resources/META-INF/services/org.apache.
commons.logging.LogFactory
Post by Matt Sicker
Post by Asma Zinneera Jabir
I am trying to set up log4j2 for Apache Commons Logging using the
*commons-logging.properties* file in an OSGi environment. For Log4j 1 I
could use org.apache.commons.logging.Log=org.apache.commons.
logging.impl.
Post by Matt Sicker
Post by Asma Zinneera Jabir
Log4JLogger which maps to version Log4j 1.2. I couldn't find out the
implementation for log4J2. The version I am using is 2.8.2.
There is a central logging component which is referred by other
components
Post by Matt Sicker
Post by Asma Zinneera Jabir
and this component bundles other needed loggers (e.g. commons-logging,
log4j/log4j2) added as dependencies.
The Log4J2 documentation for Log4J Commons Logging Bridge
<https://logging.apache.org/log4j/log4j-2.3/log4j-jcl/index.html> specifies
that by just *adding the bridge jar along with the other Log4j 2 jars
and
Post by Matt Sicker
Post by Asma Zinneera Jabir
the Commons Logging jar, all logging done using the Commons Logging API
will be routed to Log4*. I tried this by adding
- log4j-api
- log4j-core
- log4j-jcl
- commons-logging
dependencies in the *pom.xml* of the central logging component and
bundled
Post by Matt Sicker
Post by Asma Zinneera Jabir
with it without (and with just to check) using the
*commons-logging.properties* but didn't work that way. How can I
implement
Post by Matt Sicker
Post by Asma Zinneera Jabir
this with or without the commons-logging.properties?
I debugged the commons-logging source code and found in
LogFactoryImpl.java it
looks for a logging implementation (L843
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/
LogFactoryImpl.java#L843
Post by Matt Sicker
Post by Asma Zinneera Jabir
)
from a list (L162
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/
LogFactoryImpl.java#L162
Post by Matt Sicker
Post by Asma Zinneera Jabir
).
Here since the Log4JLogger does not support Log4J2 it then sets to the
next
Post by Matt Sicker
Post by Asma Zinneera Jabir
in line, that is JDK14Logger. Since the Log4J2 documentaiton says adding
the bridge simply maps the logs from JCL to Log4J2, what role does the
bridging api play here? I noticed the LogFactoryImpl.java and Log4JLog.java in
it but how does commons-logging refer to these which are in a different
package?
stackoverflow question: Apache commons-logging bridge for log4j2
<https://stackoverflow.com/questions/44839779/apache-
commons-logging-bridge-for-log4j2>
--
Matt Sicker
2017-07-07 14:22:41 UTC
Permalink
If you're using OSGi, you can try out the related project pax-logging which
provides log4j2 along with some bridges, though if I recall correctly, the
bridges are mostly via SLF4J still. Pax logging is a rather open project,
so if that's not desired, you can always send a pull request.
Post by Asma Zinneera Jabir
I went through the ServiceLoader usages and asking from what I understand.
Does this mean that on top of adding the bridge dependency in the central
logging component I also have to use the ServiceLoader in each and every
file importing commons-logging to find the LogFactoryImpl in the bridge to
overrite it?
Post by Ralph Goers
The ServiceLoader needs special handling to work in OSGi. See
http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html <
http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html>
Ralph
Post by Matt Sicker
https://github.com/apache/logging-log4j2/blob/master/
log4j-jcl/src/main/resources/META-INF/services/org.apache.
commons.logging.LogFactory
Post by Matt Sicker
Post by Asma Zinneera Jabir
I am trying to set up log4j2 for Apache Commons Logging using the
*commons-logging.properties* file in an OSGi environment. For Log4j 1
I
Post by Ralph Goers
Post by Matt Sicker
Post by Asma Zinneera Jabir
could use org.apache.commons.logging.Log=org.apache.commons.
logging.impl.
Post by Matt Sicker
Post by Asma Zinneera Jabir
Log4JLogger which maps to version Log4j 1.2. I couldn't find out the
implementation for log4J2. The version I am using is 2.8.2.
There is a central logging component which is referred by other
components
Post by Matt Sicker
Post by Asma Zinneera Jabir
and this component bundles other needed loggers (e.g. commons-logging,
log4j/log4j2) added as dependencies.
The Log4J2 documentation for Log4J Commons Logging Bridge
<https://logging.apache.org/log4j/log4j-2.3/log4j-jcl/index.html> specifies
that by just *adding the bridge jar along with the other Log4j 2 jars
and
Post by Matt Sicker
Post by Asma Zinneera Jabir
the Commons Logging jar, all logging done using the Commons Logging
API
Post by Ralph Goers
Post by Matt Sicker
Post by Asma Zinneera Jabir
will be routed to Log4*. I tried this by adding
- log4j-api
- log4j-core
- log4j-jcl
- commons-logging
dependencies in the *pom.xml* of the central logging component and
bundled
Post by Matt Sicker
Post by Asma Zinneera Jabir
with it without (and with just to check) using the
*commons-logging.properties* but didn't work that way. How can I
implement
Post by Matt Sicker
Post by Asma Zinneera Jabir
this with or without the commons-logging.properties?
I debugged the commons-logging source code and found in
LogFactoryImpl.java it
looks for a logging implementation (L843
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/
LogFactoryImpl.java#L843
Post by Matt Sicker
Post by Asma Zinneera Jabir
)
from a list (L162
<https://github.com/apache/commons-logging/blob/LOGGING_
1_2/src/main/java/org/apache/commons/logging/impl/
LogFactoryImpl.java#L162
Post by Matt Sicker
Post by Asma Zinneera Jabir
).
Here since the Log4JLogger does not support Log4J2 it then sets to the
next
Post by Matt Sicker
Post by Asma Zinneera Jabir
in line, that is JDK14Logger. Since the Log4J2 documentaiton says
adding
Post by Ralph Goers
Post by Matt Sicker
Post by Asma Zinneera Jabir
the bridge simply maps the logs from JCL to Log4J2, what role does the
bridging api play here? I noticed the LogFactoryImpl.java and Log4JLog.java in
it but how does commons-logging refer to these which are in a
different
Post by Ralph Goers
Post by Matt Sicker
Post by Asma Zinneera Jabir
package?
stackoverflow question: Apache commons-logging bridge for log4j2
<https://stackoverflow.com/questions/44839779/apache-
commons-logging-bridge-for-log4j2>
--
--
Matt Sicker <***@gmail.com>
Loading...