Question on SLF4J - binding

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

Question on SLF4J - binding

Chen, Richard - 2

Hi,

 

This is my questions: I am writing a java library which uses SLF4J and bind to simple. Next, I export my library (project) to a JAR file. I deliver the JAR to three different clients. And each client has its own application to call my library (use the JAR I delivered).

Application used by Client A does not use any logging framework.

Application used by Client B uses log4j.

Application used by Client C uses java.util.logging.

Since I am bind to simple, I understand logging wouldn’t work, but will it cause any errors/issues for having it bind to simple?

 

I appreciate if anyone can answer this question.  


This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer. If you are not the intended recipient, please delete this message.

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question on SLF4J - binding

Joachim Durchholz
On 22.02.2017 22:40, Chen, Richard - 2 wrote:
> Since I am bind to simple, I understand logging wouldn’t work, but will
> it cause any errors/issues for having it bind to simple?

Since the backend is a per-application decision, that decision should be
made by the main program, not by any library (SLF4J was built
specifically to allow libraries to do logging without committing to a
specific backend).

If you want to see log output from your test code, then your test code
should bind to a backend, yes.

That's why you typically add logging backends to the "test" scope in
Maven: These are used just during testing and not made part of the
generated jar files.

HTH
Jo
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question on SLF4J - binding

Chen, Richard - 2
Thanks for the reply, Jo.

The java library is developed by my team. Our java library doesn’t know about the main program (various clients applications). And the original goal for using SLF4J is logging for our java library, not for the main program(clients applications). I want to keep one version of our java library, in other words, having just one JAR file, (not multiple versions of JARs with different bindings). Is that possible?
And between the binding used in our java library and the logging framework used by a client's application, if they are different, will it cause any error/problem?
Thanks.



-----Original Message-----
From: slf4j-user [mailto:[hidden email]] On Behalf Of Joachim Durchholz
Sent: Wednesday, February 22, 2017 4:55 PM
To: [hidden email]
Subject: Re: [slf4j-user] Question on SLF4J - binding

On 22.02.2017 22:40, Chen, Richard - 2 wrote:
> Since I am bind to simple, I understand logging wouldn’t work, but
> will it cause any errors/issues for having it bind to simple?

Since the backend is a per-application decision, that decision should be made by the main program, not by any library (SLF4J was built specifically to allow libraries to do logging without committing to a specific backend).

If you want to see log output from your test code, then your test code should bind to a backend, yes.

That's why you typically add logging backends to the "test" scope in
Maven: These are used just during testing and not made part of the generated jar files.

HTH
Jo
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user

----------------------------------------------------------------------
This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer.   If you are not the intended recipient, please delete this message.
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question on SLF4J - binding

Chris Pratt
That is EXACTLY what SLF4j is there for.  You call the SLF4j API front-end and leave the decision about what logging engine up to whoever writes the main program.

In the example from your first message:
Application used by client A: would have to do nothing, but they would never see any output from your logging statements.
Application used by client B: would add slf4j-log4j.jar to their application and all your logging statements would show up in their normal logs (depending on how they configured the logging for your package)
Application used by client C: would add slf4j-jul.jar to their application and all your logging statements would show up in their normal logs (depending on how they configured the logging for your package)

You should not be using ANYTHING directly from the log4j-simple.jar file, only use things made public by log4j-api.jar and you will be fine.

As Joachim said, if you need to do testing on your library (a very good idea), that is when you would add the log4j-simple.jar to your test harness and the messages would magically appear in System.out.
  (*Chris*)

On Wed, Feb 22, 2017 at 2:05 PM, Chen, Richard - 2 <[hidden email]> wrote:
Thanks for the reply, Jo.

The java library is developed by my team. Our java library doesn’t know about the main program (various clients applications). And the original goal for using SLF4J is logging for our java library, not for the main program(clients applications). I want to keep one version of our java library, in other words, having just one JAR file, (not multiple versions of JARs with different bindings). Is that possible?
And between the binding used in our java library and the logging framework used by a client's application, if they are different, will it cause any error/problem?
Thanks.



-----Original Message-----
From: slf4j-user [mailto:[hidden email]] On Behalf Of Joachim Durchholz
Sent: Wednesday, February 22, 2017 4:55 PM
To: [hidden email]
Subject: Re: [slf4j-user] Question on SLF4J - binding

On <a href="tel:22.02.2017%2022" value="+12202201722">22.02.2017 22:40, Chen, Richard - 2 wrote:
> Since I am bind to simple, I understand logging wouldn’t work, but
> will it cause any errors/issues for having it bind to simple?

Since the backend is a per-application decision, that decision should be made by the main program, not by any library (SLF4J was built specifically to allow libraries to do logging without committing to a specific backend).

If you want to see log output from your test code, then your test code should bind to a backend, yes.

That's why you typically add logging backends to the "test" scope in
Maven: These are used just during testing and not made part of the generated jar files.

HTH
Jo
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user

----------------------------------------------------------------------
This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer.   If you are not the intended recipient, please delete this message.
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user


_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question on SLF4J - binding

Chen, Richard - 2

Thanks a lot for your reply Chris

 

From: slf4j-user [mailto:[hidden email]] On Behalf Of Chris Pratt
Sent: Wednesday, February 22, 2017 5:41 PM
To: User list for the slf4j project
Subject: Re: [slf4j-user] Question on SLF4J - binding

 

That is EXACTLY what SLF4j is there for.  You call the SLF4j API front-end and leave the decision about what logging engine up to whoever writes the main program.

 

In the example from your first message:

Application used by client A: would have to do nothing, but they would never see any output from your logging statements.

Application used by client B: would add slf4j-log4j.jar to their application and all your logging statements would show up in their normal logs (depending on how they configured the logging for your package)

Application used by client C: would add slf4j-jul.jar to their application and all your logging statements would show up in their normal logs (depending on how they configured the logging for your package)

 

You should not be using ANYTHING directly from the log4j-simple.jar file, only use things made public by log4j-api.jar and you will be fine.

 

As Joachim said, if you need to do testing on your library (a very good idea), that is when you would add the log4j-simple.jar to your test harness and the messages would magically appear in System.out.

  (*Chris*)

 

On Wed, Feb 22, 2017 at 2:05 PM, Chen, Richard - 2 <[hidden email]> wrote:

Thanks for the reply, Jo.

The java library is developed by my team. Our java library doesn’t know about the main program (various clients applications). And the original goal for using SLF4J is logging for our java library, not for the main program(clients applications). I want to keep one version of our java library, in other words, having just one JAR file, (not multiple versions of JARs with different bindings). Is that possible?
And between the binding used in our java library and the logging framework used by a client's application, if they are different, will it cause any error/problem?
Thanks.




-----Original Message-----
From: slf4j-user [mailto:[hidden email]] On Behalf Of Joachim Durchholz
Sent: Wednesday, February 22, 2017 4:55 PM
To: [hidden email]
Subject: Re: [slf4j-user] Question on SLF4J - binding

On <a href="tel:22.02.2017%2022">22.02.2017 22:40, Chen, Richard - 2 wrote:
> Since I am bind to simple, I understand logging wouldn’t work, but
> will it cause any errors/issues for having it bind to simple?

Since the backend is a per-application decision, that decision should be made by the main program, not by any library (SLF4J was built specifically to allow libraries to do logging without committing to a specific backend).

If you want to see log output from your test code, then your test code should bind to a backend, yes.

That's why you typically add logging backends to the "test" scope in
Maven: These are used just during testing and not made part of the generated jar files.

HTH
Jo
_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user

----------------------------------------------------------------------
This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer.   If you are not the intended recipient, please delete this message.

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user

 


This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer. If you are not the intended recipient, please delete this message.

_______________________________________________
slf4j-user mailing list
[hidden email]
http://mailman.qos.ch/mailman/listinfo/slf4j-user
Loading...