You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Dulanjanie <du...@wso2.com> on 2008/10/29 04:54:22 UTC

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


RE: How to create client based log levels for a service

Posted by Dulanjanie <du...@wso2.com>.
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


Re: How to create client based log levels for a service

Posted by Dulanjanie <du...@wso2.com>.
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" <dz...@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" <dz...@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


Re: How to create client based log levels for a service

Posted by Jacob Kjome <ho...@visi.com>.
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" <dz...@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" <dz...@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


RE: How to create client based log levels for a service

Posted by Dong Zhang <dz...@seven.com>.
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" <dz...@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


Re: How to create client based log levels for a service

Posted by Jacob Kjome <ho...@visi.com>.
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" <dz...@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


RE: How to create client based log levels for a service

Posted by Dong Zhang <dz...@seven.com>.
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