[logback-user] Legacy Log4j Question

Robert Elliot rob at lidalia.org.uk
Wed Oct 27 15:08:17 CEST 2010


Ceki's said in the past that the answer is no.  After all, what would it do?  You have to bear in mind that it's intended to redirect log4j to slf4j - so it has to be slf4j implementation agnostic.  So it can't actually *do* anything with programmatic attempts to change the levels of Logger instances or add Appenders; the most you could have is a no operation implementation.  That would probably result in loads of null pointer exceptions as your dependent jars try to use objects retrieved via the API, not to mention that if your dependent jars actually need to do these things then they will be broken even if no exception is thrown immediately.

(One possibility I could see is adding all the classes and methods to be binary compatible but making all the methods throw an UnsupportedOperationException explaining why log4j-over-slf4j only implements a small subset of log4j's API so that people aren't left wondering about ClassNotFoundExceptions - which might have saved you having this conversation, but wouldn't actually solve your problem.)

If you have a hard dependency on log4j that you can't change then I guess you have to use log4j.

----- Original Message -----
> From: "Jeremy Truelove" <Jeremy.Truelove at barclayscapital.com>
> To: logback-user at qos.ch
> Sent: Wednesday, 27 October, 2010 1:58:27 PM
> Subject: Re: [logback-user] Legacy Log4j Question
> Unfortunately I don't have the ability to change these dependencies
> and I don't know why they are coded in the way they are so they have
> such a hard dependency on log4j. Is there any plan to add the rest of
> the classes to log4j-over-slf4j just to support legacy jar dependency
> issues?
> 
> -----Original Message-----
> From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch]
> On Behalf Of Robert Elliot
> Sent: Wednesday, October 27, 2010 8:46 AM
> To: logback users list
> Subject: Re: [logback-user] Legacy Log4j Question
> 
> The question has to be why do your dependent jars need to call these
> APIs in log4j? Unfortunately log4j does not differentiate between the
> interface for firing off log events (the sort of thing SLF4J/Commons
> logging provide) and its API for managing what is actually done for
> them. As a general rule libraries should only be using the bare
> minimum of logging (the equivalent of the SLF4J interface - which is
> what log4j-over-slf4j implements) and only the end user application
> should be defining things like appenders and turning logging on or
> off.
> 
> If your dependent jars are using the log4j API for controlling what is
> done with logging events then either they have a real dependency on
> log4j for some good reason or else they are behaving badly. Without
> knowing what these dependencies are, what they are doing and why
> there's not much else can be said.
> 
> (Of course you always have the option of using log4j as your slf4j
> implementation via slf4j-log4j; you can still pipe JULI & Commons
> Logging to SLF4J and use SLF4J in your own code and so end up with a
> single logging config file, just a log4j one rather than a logback
> one.)
> 
> ----- Original Message -----
> > From: "Jeremy Truelove" <Jeremy.Truelove at barclayscapital.com>
> > To: logback-user at qos.ch
> > Sent: Wednesday, 27 October, 2010 1:30:22 PM
> > Subject: [logback-user] Legacy Log4j Question
> > So I've been porting some of our services to use Logback over log4j
> > and I've been using the log4j-over-slf4j jar to spoof log4j for our
> > legacy dependencies. The only issue is log4j-over-slf4j doesn't
> > implement many of the classes of log4j so I'm seeing a decent few
> > class not found exceptions from dependent jars. How have people got
> > around this? Is it enough to just put the nlog4j in your classpath
> > instead of the log4j-over-slf4j jar? I’d still like to use one
> > logback
> > config file to drive all my logging to a single log file. Thanks.
> >
> > jt
> >
> > _______________________________________________
> >
> >
> >
> > This e-mail may contain information that is confidential, privileged
> > or otherwise protected from disclosure. If you are not an intended
> > recipient of this e-mail, do not duplicate or redistribute it by any
> > means. Please delete it and any attachments and notify the sender
> > that
> > you have received it in error. Unless specifically indicated, this
> > e-mail is not an offer to buy or sell or a solicitation to buy or
> > sell
> > any securities, investment products or other financial product or
> > service, an official confirmation of any transaction, or an official
> > statement of Barclays. Any views or opinions presented are solely
> > those of the author and do not necessarily represent those of
> > Barclays. This e-mail is subject to terms available at the following
> > link: www.barcap.com/emaildisclaimer . By messaging with Barclays
> > you
> > consent to the foregoing. Barclays Capital is the investment banking
> > division of Barclays Bank PLC, a company registered in England
> > (number
> > 1026167) with its registered office at 1 Churchill Place, London,
> > E14
> > 5HP. This email may relate to or be sent from other members of the
> > Barclays Group.
> >
> > _______________________________________________
> > _______________________________________________
> > Logback-user mailing list
> > Logback-user at qos.ch
> > http://qos.ch/mailman/listinfo/logback-user
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user


More information about the Logback-user mailing list