logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dulanjanie <dulanja...@wso2.com>
Subject Re: How to create client based log levels for a service
Date Mon, 03 Nov 2008 03:54:58 GMT
this thread was also useful to me...
http://www.mail-archive.com/log4j-user@logging.apache.org/msg00912.html


On Thu, 2008-10-30 at 07:54 -0500, Jacob Kjome wrote:
> Use a list search tool, such as...
> 
> http://marc.info/?l=log4j-user
> http://log4j-user.markmail.org/
> 
> Jake
> 
> On Wed, 29 Oct 2008 18:19:44 -0700
>   "Dong Zhang" <dzhang@seven.com> wrote:
> > Hi Jake,
> > 
> > I just joined the mail list for a few days, a pity that I missed those 
> >topics. 
> > It's really appreciated if you can point me to some links related.
> > 
> > Thanks,
> > Dong
> > -----Original Message-----
> >From: Jacob Kjome [mailto:hoju@visi.com] 
> > Sent: Wednesday, October 29, 2008 10:13 PM
> > To: Log4J Users List
> > Subject: Re: How to create client based log levels for a service
> > 
> > extending Logger should not be necessary.  Search the list for custom 
> > repository selectors or logging per/user or per/thread.  This topic has been 
> > covered quite a number of times.  I believe people have posted custom 
> > repository selectors that meet this need.  I think the gist is that the 
> > selector would choose the logger repository based on an MDC value.  So, for 
> > instance, in a webapp, you would use a servlet filter to set the MDC value.  
> > Then the selector will use that value to choose the logger repository, each 
> > with its own configuration.
> > 
> > Jake
> > 
> > On Tue, 28 Oct 2008 22:38:02 -0700
> >  "Dong Zhang" <dzhang@seven.com> wrote:
> >> Hi,
> >> 
> >> I just resolved such kind of problem.
> >> I believe the service you mentioned is a multithread program, and each 
> >>client would run in its own thread (either new a Thread for everyone, or from

> >>a Thread pool in my case).
> >> 
> >> Let's call it custom logging, the basic idea is use the ThreadLocal to mark

> >>a Thread if it need to enable custom logging:
> >> 1. Have a static ThreadLocal<Boolean> object called isCustomLoggingEnabled

> >>in any where it can be accessed.I put it in MyLogger bellow.
> >> 2. Extend org.apache.log4j.Logger, say, MyLogger. Override 
> >>getEffectiveLevel() method. Like this:
> >> -----------------------------------
> >>    public Level getEffectiveLevel() {
> >>        if(isCustomLoggingEnabled.get().booleanValue()) {
> >>            return SevenLoggerAdmin.DEBUG;//any level you want.
> >>        } else {
> >>            return super.getEffectiveLevel();
> >>        }
> >>    }
> >> -----------------------------------
> >> 
> >> 3. At the beginning of run(), which means at the beginning of each thread, 
> >>judge if the IP is the one you want to enable:
> >> Public void run() {
> >>    //if IP == y then
> >>        MyLogger. isCustomLoggingEnabled.set(new Boolean(true))
> >> 
> >> //other logic
> >> 
> >> //reset the flag, if the Thread is shared.
> >> MyLogger. isCustomLoggingEnabled.set(new Boolean(false))
> >> }
> >> 
> >> Please let me know if you have any question.
> >> 
> >> Good luck,
> >> Dong
> >> -----Original Message-----
> >>From: Dulanjanie [mailto:dulanjanie@wso2.com] 
> >> Sent: Wednesday, October 29, 2008 11:54 AM
> >> To: log4j-user@logging.apache.org
> >> Subject: How to create client based log levels for a service
> >> 
> >> 
> >> --
> >> Hi,
> >> What i want to do is, change log levels for a certain service based on
> >> client IP.
> >> say, "increase log level for service x when requests are made by y" 
> >> 
> >> Does anyone have any idea on how to do this?
> >> Is it possible using NDC or MDC?
> >> Any help is very much appreciated!
> >> 
> >> 
> >> 
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>For additional commands, e-mail: log4j-user-help@logging.apache.org
> >> 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >For additional commands, e-mail: log4j-user-help@logging.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
-- 



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


Mime
View raw message