[logback-user] How to redirect log4j and other to logback ?

BAKHTI Mohammed onlymed at hotmail.com
Sun Aug 28 00:03:51 CEST 2011


Hello David, 

I'm not writting SLF4J i'm just using logback in programmatically configuration way. The idea is to have a logger configured inside an API which will be used by all the other applications, so i have created just some classes (with apprenders...)  which implements logger and call super.debug.... and add my other functions ( with specific behaviors : ie mytrace will send entry data to an activemq...) . in this class i configure all the appenders and attach them to the root logger . this way if an application is using a file logback.xml it will be ignored (actually the configuration will be rewrited by my api) 

As those classes uses Appender and other stuff that are not implemented (not yet) in log4j-over-slf4j  so can't be used 

So now to get log4j logs to be redirected to my API i use a something like : 

create a class which extends log4j appender, transfrom the log4j LoggingEvent to logback LoggingEvent and then call doAppend of my API

Log4j config : 

log4j.rootLogger=INFO, out

# Log level for each package

#Redirect all log4j calls to my api 
log4j.appender.out=com.company.api.tool.Log4JWrapper

Is there any other way more clean to do that ?

Thanks 

> CC: logback-user at qos.ch
> From: nabble at diroussel.xsmail.com
> Date: Sat, 27 Aug 2011 20:14:54 +0100
> To: logback-user at qos.ch
> Subject: Re: [logback-user] How to redirect log4j and other to logback ?
> 
> The logback docs cover redirecting log4j to slf4j. 
> 
> Are you saying you've written you own slf4j backend?
> 
> David
> 
> On 26 Aug 2011, at 15:29, BAKHTI Mohammed <onlymed at hotmail.com> wrote:
> 
> > 
> > Hello, 
> > 
> > I have an api (jar) where i configure logback appenders and loggers (in code) and add some other functions (mytraceAction()...) which will be used by all my other projects 
> > 
> > the idea is to give all projects an api so they have just to  getInstance() and log  (the functions added are for access and actions trace over JMS appender)
> > 
> > Everything is working well the question is about the other API which use : log4j jcl ... how can i got their log and treat them in my api ? is it possible ?
> > 
> > i tried to use jcl-over-slf4j ... but when they are in my libs i just don't see any other logs then those who use my api (means no spring, hibernate ... logs )
> > 
> > thanks 
> > 
> > 
> > _______________________________________________
> > 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
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20110828/1e0461dc/attachment-0001.html>


More information about the Logback-user mailing list