Apache commons-logging bridge for log4j2

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Apache commons-logging bridge for log4j2

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>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apache commons-logging bridge for log4j2

Matt Sicker
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

On 5 July 2017 at 03:30, Asma Zinneera Jabir <[hidden email]> wrote:

> 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 <[hidden email]>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apache commons-logging bridge for log4j2

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

> On Jul 5, 2017, at 10:27 AM, Matt Sicker <[hidden email]> wrote:
>
> 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
>
> On 5 July 2017 at 03:30, Asma Zinneera Jabir <[hidden email]> wrote:
>
>> 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 <[hidden email]>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apache commons-logging bridge for log4j2

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?

On Wed, Jul 5, 2017 at 10:59 PM, Ralph Goers <[hidden email]>
wrote:

> 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
>
> > On Jul 5, 2017, at 10:27 AM, Matt Sicker <[hidden email]> wrote:
> >
> > 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
> >
> > On 5 July 2017 at 03:30, Asma Zinneera Jabir <[hidden email]>
> wrote:
> >
> >> 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 <[hidden email]>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Apache commons-logging bridge for log4j2

Matt Sicker
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.

On 7 July 2017 at 00:49, Asma Zinneera Jabir <[hidden email]> wrote:

> 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?
>
> On Wed, Jul 5, 2017 at 10:59 PM, Ralph Goers <[hidden email]>
> wrote:
>
> > 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
> >
> > > On Jul 5, 2017, at 10:27 AM, Matt Sicker <[hidden email]> wrote:
> > >
> > > 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
> > >
> > > On 5 July 2017 at 03:30, Asma Zinneera Jabir <[hidden email]>
> > wrote:
> > >
> > >> 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 <[hidden email]>
> >
> >
>



--
Matt Sicker <[hidden email]>
Loading...