You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Usha Nayak <us...@gmail.com> on 2023/01/24 23:01:16 UTC

log4j2 API and JUL logging framework

Hello All,

As a library owner, if I were to use the log4j2 API and the application
that uses my library has a java.util.logging ( JUL ) framework.

What adapter or routing jars will be needed at runtime by application such
that all the logs, both from the library and the application, end up using
the same logging framework implementation (JUL) ?

Any help greatly appreciated

Thanks

Re: log4j2 API and JUL logging framework

Posted by Usha Nayak <us...@gmail.com>.
Thank you again..


On Wed, Jan 25, 2023 at 10:45 AM Ralph Goers <ra...@dslextreme.com>
wrote:

> Volkan,
>
> I am not sure what question you are answering but it doesn’t look like the
> question that was asked. To answer his question you would need to replace
> log4j-core with log4j-to-jul as a dependency.
>
> Ralph
>
> > On Jan 25, 2023, at 2:05 AM, Volkan Yazıcı <vo...@yazi.ci> wrote:
> >
> > That is a really good question addressing a concern that should be shared
> > by every single Java library developer out there, Usha. We sadly don't
> have
> > an official answer to this – we should and maybe who knows, you can
> > contribute that to the Log4j manual! But let me share my take on the
> matter.
> >
> > Libraries should only depend on logging APIs (SLF4J, Log4j, JUL, JCL,
> JPL,
> > etc.) and only provide an implementation (Log4j, Logback, etc.) for their
> > tests. Let me try to get it as concrete as possible by sharing what you
> > need to have in your `pom.xml`:
> >
> > <dependencyManagement>
> >  <dependencies>
> >
> >    <dependency>
> >      <groupId>org.apache.logging.log4j</groupId>
> >      <artifactId>log4j-bom</artifactId>
> >      <version>${log4j2.version}</version>
> >      <type>pom</type>
> >      <scope>import</scope>
> >    </dependency>
> >
> >  <dependencies>
> > <dependencyManagement>
> >
> > <dependencies>
> >
> >  <dependency>
> >    <groupId>org.apache.logging.log4j</groupId>
> >    <artifactId>log4j-api</artifactId>
> >  </dependency>
> >
> >  <dependency>
> >    <groupId>org.apache.logging.log4j</groupId>
> >    <artifactId>log4j-core</artifactId>
> >    <scope>test</scope>
> >  </dependency>
> >
> >  <!-- If you have dependencies that use other logging APIs
> >        than Log4j (SLF4J, JUL, JCL, JPL, etc.), add their bridges
> >        here as `test` dependencies -->
> >
> > </dependencies>
> >
> > Next you add a minimal `log4j2.xml` to `src/test/resources` and you are
> > done.
> >
> > It is the responsibility of the application which will be glueing all
> these
> > libraries together to decide on where to and how to bind all these
> logging
> > APIs. As a matter of fact, many modern application frameworks provide
> > goodies to save you from that burden; consider
> `spring-boot-starter-log4j2`.
> >
> > On Wed, Jan 25, 2023 at 12:01 AM Usha Nayak <us...@gmail.com> wrote:
> >
> >> Hello All,
> >>
> >> As a library owner, if I were to use the log4j2 API and the application
> >> that uses my library has a java.util.logging ( JUL ) framework.
> >>
> >> What adapter or routing jars will be needed at runtime by application
> such
> >> that all the logs, both from the library and the application, end up
> using
> >> the same logging framework implementation (JUL) ?
> >>
> >> Any help greatly appreciated
> >>
> >> Thanks
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: log4j2 API and JUL logging framework

Posted by Ralph Goers <ra...@dslextreme.com>.
Volkan,

I am not sure what question you are answering but it doesn’t look like the question that was asked. To answer his question you would need to replace log4j-core with log4j-to-jul as a dependency.

Ralph

> On Jan 25, 2023, at 2:05 AM, Volkan Yazıcı <vo...@yazi.ci> wrote:
> 
> That is a really good question addressing a concern that should be shared
> by every single Java library developer out there, Usha. We sadly don't have
> an official answer to this – we should and maybe who knows, you can
> contribute that to the Log4j manual! But let me share my take on the matter.
> 
> Libraries should only depend on logging APIs (SLF4J, Log4j, JUL, JCL, JPL,
> etc.) and only provide an implementation (Log4j, Logback, etc.) for their
> tests. Let me try to get it as concrete as possible by sharing what you
> need to have in your `pom.xml`:
> 
> <dependencyManagement>
>  <dependencies>
> 
>    <dependency>
>      <groupId>org.apache.logging.log4j</groupId>
>      <artifactId>log4j-bom</artifactId>
>      <version>${log4j2.version}</version>
>      <type>pom</type>
>      <scope>import</scope>
>    </dependency>
> 
>  <dependencies>
> <dependencyManagement>
> 
> <dependencies>
> 
>  <dependency>
>    <groupId>org.apache.logging.log4j</groupId>
>    <artifactId>log4j-api</artifactId>
>  </dependency>
> 
>  <dependency>
>    <groupId>org.apache.logging.log4j</groupId>
>    <artifactId>log4j-core</artifactId>
>    <scope>test</scope>
>  </dependency>
> 
>  <!-- If you have dependencies that use other logging APIs
>        than Log4j (SLF4J, JUL, JCL, JPL, etc.), add their bridges
>        here as `test` dependencies -->
> 
> </dependencies>
> 
> Next you add a minimal `log4j2.xml` to `src/test/resources` and you are
> done.
> 
> It is the responsibility of the application which will be glueing all these
> libraries together to decide on where to and how to bind all these logging
> APIs. As a matter of fact, many modern application frameworks provide
> goodies to save you from that burden; consider `spring-boot-starter-log4j2`.
> 
> On Wed, Jan 25, 2023 at 12:01 AM Usha Nayak <us...@gmail.com> wrote:
> 
>> Hello All,
>> 
>> As a library owner, if I were to use the log4j2 API and the application
>> that uses my library has a java.util.logging ( JUL ) framework.
>> 
>> What adapter or routing jars will be needed at runtime by application such
>> that all the logs, both from the library and the application, end up using
>> the same logging framework implementation (JUL) ?
>> 
>> Any help greatly appreciated
>> 
>> Thanks
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: log4j2 API and JUL logging framework

Posted by Volkan Yazıcı <vo...@yazi.ci>.
That is a really good question addressing a concern that should be shared
by every single Java library developer out there, Usha. We sadly don't have
an official answer to this – we should and maybe who knows, you can
contribute that to the Log4j manual! But let me share my take on the matter.

Libraries should only depend on logging APIs (SLF4J, Log4j, JUL, JCL, JPL,
etc.) and only provide an implementation (Log4j, Logback, etc.) for their
tests. Let me try to get it as concrete as possible by sharing what you
need to have in your `pom.xml`:

<dependencyManagement>
  <dependencies>

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-bom</artifactId>
      <version>${log4j2.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>

  <dependencies>
<dependencyManagement>

<dependencies>

  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
  </dependency>

  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <scope>test</scope>
  </dependency>

  <!-- If you have dependencies that use other logging APIs
        than Log4j (SLF4J, JUL, JCL, JPL, etc.), add their bridges
        here as `test` dependencies -->

</dependencies>

Next you add a minimal `log4j2.xml` to `src/test/resources` and you are
done.

It is the responsibility of the application which will be glueing all these
libraries together to decide on where to and how to bind all these logging
APIs. As a matter of fact, many modern application frameworks provide
goodies to save you from that burden; consider `spring-boot-starter-log4j2`.

On Wed, Jan 25, 2023 at 12:01 AM Usha Nayak <us...@gmail.com> wrote:

> Hello All,
>
> As a library owner, if I were to use the log4j2 API and the application
> that uses my library has a java.util.logging ( JUL ) framework.
>
> What adapter or routing jars will be needed at runtime by application such
> that all the logs, both from the library and the application, end up using
> the same logging framework implementation (JUL) ?
>
> Any help greatly appreciated
>
> Thanks
>

Re: log4j2 API and JUL logging framework

Posted by Ralph Goers <ra...@dslextreme.com>.
The log4j-jul module is what maps anyone coding to java.util.logging to use Log4j 2 as the recommendation. The log4j-to-jul module is used when Log4j 2 is the API and java.util.logging is the implementation.

Note that log4j-to-jul is fairly new. It was introduced by LOG4J2-3282 in Jira in Jan 2022 as a user contribution, although it has had a few minor modifications since then.

Ralph

> On Jan 24, 2023, at 6:44 PM, Usha Nayak <us...@gmail.com> wrote:
> 
> Thank you all for your response.
> 
> I did look through the documentation.  However, the impression I got from the 'Using log4j2 with JUL' section was that log4j2 is used as a logging framework (application uses JUL lib and with 'log4j-jul' bridge connects to log4j2 logging framework) . In my case, it's an opposite requirement.
> 
> I did come across below though in FAQ section:
> 
> 
> 
> 
> 
> which makes me think that an application ( who are consumers of my lib, which is based of log4j2 API ) will need log4j-to-slf4j-2.x.jar, slf4j-api.jar,slf4j-jdk14.jar (jul binding for slf4j delegating all slf4j calls to be  JUL ) 
> 
> On the other hand, if my lib were to be based of slf4j API, then the applications (consumers of my lib ) will only need slf4j-jdk14.jar 
> 
> My understanding is a library should be based on only an api jar and nothing else and it's an application that'll provide the bindings. With the log4j2 API, there are quite a few bindings that applications will need to be aware of. Am I missing something?
> 
> Thanks. Regards
> 
>  
> 
> 
> 
> 
> On Tue, Jan 24, 2023 at 7:31 PM Gary Gregory <garydgregory@gmail.com <ma...@gmail.com>> wrote:
>> How about https://logging.apache.org/log4j/2.x/manual/api-separation.html
>> 
>> Gary
>> 
>> On Tue, Jan 24, 2023, 18:31 Matt Sicker <matt@musigma.org <ma...@musigma.org>> wrote:
>> 
>> > That’s the log4j-to-jul module. I can’t find a link on the site, but
>> > here’s the module overview page:
>> > https://logging.apache.org/log4j/2.x/log4j-to-jul/index.html
>> >
>> > > On Jan 24, 2023, at 5:01 PM, Usha Nayak <ushanay@gmail.com <ma...@gmail.com>> wrote:
>> > >
>> > > Hello All,
>> > >
>> > > As a library owner, if I were to use the log4j2 API and the application
>> > > that uses my library has a java.util.logging ( JUL ) framework.
>> > >
>> > > What adapter or routing jars will be needed at runtime by application
>> > such
>> > > that all the logs, both from the library and the application, end up
>> > using
>> > > the same logging framework implementation (JUL) ?
>> > >
>> > > Any help greatly appreciated
>> > >
>> > > Thanks
>> >
>> >


Re: log4j2 API and JUL logging framework

Posted by Usha Nayak <us...@gmail.com>.
Thank you all for your response.

I did look through the documentation.  However, the impression I got from
the 'Using log4j2 with JUL' section was that log4j2 is used as a logging
framework (application uses JUL lib and with 'log4j-jul' bridge connects to
log4j2 logging framework) . In my case, it's an opposite requirement.

I did come across below though in FAQ section:

[image: image.png]

[image: image.png]

which makes me think that an application ( who are consumers of my lib,
which is based of log4j2 API ) will need log4j-to-slf4j-2.x.jar,
slf4j-api.jar,slf4j-jdk14.jar (jul binding for slf4j delegating all slf4j
calls to be  JUL )

On the other hand, if my lib were to be based of slf4j API, then the
applications (consumers of my lib ) will only need slf4j-jdk14.jar

My understanding is a library should be based on only an api jar and
nothing else and it's an application that'll provide the bindings. With the
log4j2 API, there are quite a few bindings that applications will need to
be aware of. Am I missing something?

Thanks. Regards






On Tue, Jan 24, 2023 at 7:31 PM Gary Gregory <ga...@gmail.com> wrote:

> How about https://logging.apache.org/log4j/2.x/manual/api-separation.html
>
> Gary
>
> On Tue, Jan 24, 2023, 18:31 Matt Sicker <ma...@musigma.org> wrote:
>
> > That’s the log4j-to-jul module. I can’t find a link on the site, but
> > here’s the module overview page:
> > https://logging.apache.org/log4j/2.x/log4j-to-jul/index.html
> >
> > > On Jan 24, 2023, at 5:01 PM, Usha Nayak <us...@gmail.com> wrote:
> > >
> > > Hello All,
> > >
> > > As a library owner, if I were to use the log4j2 API and the application
> > > that uses my library has a java.util.logging ( JUL ) framework.
> > >
> > > What adapter or routing jars will be needed at runtime by application
> > such
> > > that all the logs, both from the library and the application, end up
> > using
> > > the same logging framework implementation (JUL) ?
> > >
> > > Any help greatly appreciated
> > >
> > > Thanks
> >
> >
>

Re: log4j2 API and JUL logging framework

Posted by Gary Gregory <ga...@gmail.com>.
How about https://logging.apache.org/log4j/2.x/manual/api-separation.html

Gary

On Tue, Jan 24, 2023, 18:31 Matt Sicker <ma...@musigma.org> wrote:

> That’s the log4j-to-jul module. I can’t find a link on the site, but
> here’s the module overview page:
> https://logging.apache.org/log4j/2.x/log4j-to-jul/index.html
>
> > On Jan 24, 2023, at 5:01 PM, Usha Nayak <us...@gmail.com> wrote:
> >
> > Hello All,
> >
> > As a library owner, if I were to use the log4j2 API and the application
> > that uses my library has a java.util.logging ( JUL ) framework.
> >
> > What adapter or routing jars will be needed at runtime by application
> such
> > that all the logs, both from the library and the application, end up
> using
> > the same logging framework implementation (JUL) ?
> >
> > Any help greatly appreciated
> >
> > Thanks
>
>

Re: log4j2 API and JUL logging framework

Posted by Matt Sicker <ma...@musigma.org>.
That’s the log4j-to-jul module. I can’t find a link on the site, but here’s the module overview page: https://logging.apache.org/log4j/2.x/log4j-to-jul/index.html

> On Jan 24, 2023, at 5:01 PM, Usha Nayak <us...@gmail.com> wrote:
> 
> Hello All,
> 
> As a library owner, if I were to use the log4j2 API and the application
> that uses my library has a java.util.logging ( JUL ) framework.
> 
> What adapter or routing jars will be needed at runtime by application such
> that all the logs, both from the library and the application, end up using
> the same logging framework implementation (JUL) ?
> 
> Any help greatly appreciated
> 
> Thanks