Return-Path: Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: (qmail 8641 invoked from network); 30 Oct 2008 12:58:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Oct 2008 12:58:08 -0000 Received: (qmail 52600 invoked by uid 500); 30 Oct 2008 12:58:06 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 52581 invoked by uid 500); 30 Oct 2008 12:58:06 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 52570 invoked by uid 99); 30 Oct 2008 12:58:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Oct 2008 05:58:06 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of hoju@visi.com designates 208.42.176.221 as permitted sender) Received: from [208.42.176.221] (HELO g2host.com) (208.42.176.221) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Oct 2008 12:56:49 +0000 Received: from [162.136.192.1] (account hoju@visi.com) by mailback2.g2host.com (CommuniGate Pro WEBUSER 5.1.16) with HTTP id 11626788 for log4j-user@logging.apache.org; Thu, 30 Oct 2008 07:54:19 -0500 From: "Jacob Kjome" Subject: Re: How to create client based log levels for a service To: "Log4J Users List" X-Mailer: CommuniGate Pro WebUser v5.1.16 Date: Thu, 30 Oct 2008 07:54:19 -0500 Message-ID: In-Reply-To: <8627DB75EF47C144AFADAA36BEB2BD28010D3F12@RWC-EX1.corp.seven.com> References: <1225252462.5780.3.camel@dulanjanie-desktop> <8627DB75EF47C144AFADAA36BEB2BD28010D3F0B@RWC-EX1.corp.seven.com> <8627DB75EF47C144AFADAA36BEB2BD28010D3F12@RWC-EX1.corp.seven.com> MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8;format="flowed" Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org 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" 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" 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 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