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 Wed, 29 Oct 2008 08:25:05 GMT
thanks!
I'll try it out!

On Tue, 2008-10-28 at 22:38 -0700, Dong Zhang 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


Mime
View raw message