[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpclient-commons-dev
Subject:    Re: HC 5.0 scope and design decisions
From:       Gary Gregory <garydgregory () gmail ! com>
Date:       2016-09-30 21:50:24
Message-ID: CACZkXPzTXpAhvM16PBwGvGkS7pJ5nHhT0_O3uNBk-y=0_v13iw () mail ! gmail ! com
[Download RAW message or body]


On Fri, Sep 30, 2016 at 1:15 AM, Julian Sedding <jsedding@apache.org> wrote:

> Hi all
>
> I am not familiar with log4j2, but have used slf4j extensively over
> the last years.
>
> As I understand log4j2 clearly separates its API from the
> implementation. If this is true, are there any major benefits to using
> the log4j2 API over the slf4j API?
>
> If this is not the case, and the benefits of log4j2 are predominantly
> in the implementation, then it may be sensible to code against the
> slf4j API and leave the choice of the implementation to the
> deployment. I.e. it would be possible to use log4j2 as the logging
> implementation via its slf4j binding[0].
>

From the Log4j 2 FAQ [
https://logging.apache.org/log4j/2.x/faq.html#api-tradeoffs]:

The Log4j 2 API and SLF4J have a lot in common. They both share the
objective of cleanly separating the logging API from the implementation. We
believe that the Log4j 2 API can help make your application more performant
while offering more functionality and more flexibility.

There may be a concern that using the Log4j 2 API will tightly couple your
application to Log4j 2. This is not the case: applications coded to the
Log4j 2 API always have the option to use any SLF4J-compliant library as
their logging implementation with the log4j-to-slf4j adapter. See the which
jars
<https://logging.apache.org/log4j/2.x/faq.html#which_jars_log4j-to-slf4j> FAQ
entry for details.

There are several advantages to using the Log4j 2 API:

   - SLF4J forces your application to log Strings. The Log4j 2 API supports
   logging any CharSequence if you want to log text, but also supports logging
   any Object as is. It is the responsibility of the logging
   *implementation* to handle this object, and we consider it a design
   mistake to limit applications to logging Strings.
   - The Log4j 2 API offers support for logging Message objects
   <https://logging.apache.org/log4j/2.x/manual/messages.html>. Messages
   allow support for interesting and complex constructs to be passed through
   the logging system and be efficiently manipulated. Users are free to create
   their own Message types and write custom Layouts, Filters and Lookups to
   manipulate them.
   - The Log4j 2 API has support for Java 8 lambda expressions
   <https://logging.apache.org/log4j/2.x/manual/api.html#LambdaSupport>.
   - The Log4j 2 API has better support for garbage-free logging
   <https://logging.apache.org/log4j/2.x/manual/garbagefree.html>: it
   avoids creating vararg arrays and avoids creating Strings when logging
   CharSequence objects.

I'm not interested in porting the the HC code from ACL to Slf4j, but I'll
do the port to Log4j2 ;-)

Gary

>
> I am sure others, especially Gary, can provide more qualified opinions
> here.
>
> Regards
> Julian
>
> [0] https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/index.html
>
>
> On Thu, Sep 29, 2016 at 10:00 PM, Oleg Kalnichevski <olegk@apache.org>
> wrote:
> > On Thu, 2016-09-29 at 09:27 +0530, Asankha C. Perera wrote:
> >> Hi Oleg
> >
> > ...
> >
> >> > Should be remain faithful to Commons Logging or shall we finally
> migrate
> >> > to SLF4J?
> >> I agree with Gary that Log4J2 is better than SLF4J too. Since we also
> >> have Gary's experience and support to move to it, I think that maybe the
> >> best option.
> >>
> >> regards
> >> asankha
> >>
> >
> > Gary, Asankha
> >
> > Being a happy user of Log4J2 myself I would be very much in favor of
> > using it directly. However we ought not impose a particular choice of
> > the logging toolkit upon all our users. We should be using a logging
> > bridge. This essentially leaves with two options: Commons Logging or
> > SLF4J, both of which can use different backends including Log4J2.
> >
> > Oleg
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> > For additional commands, e-mail: dev-help@hc.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic