Return-Path: Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: (qmail 53735 invoked from network); 22 May 2005 18:34:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 May 2005 18:34:08 -0000 Received: (qmail 63507 invoked by uid 500); 22 May 2005 18:34:04 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 63482 invoked by uid 500); 22 May 2005 18:34:04 -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 63465 invoked by uid 99); 22 May 2005 18:34:03 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: 204.127.202.59 is neither permitted nor denied by domain of hoju@visi.com) Received: from sccrmhc14.comcast.net (HELO sccrmhc14.comcast.net) (204.127.202.59) by apache.org (qpsmtpd/0.28) with ESMTP; Sun, 22 May 2005 11:34:02 -0700 Received: from nicki.visi.com (c-66-41-141-26.hsd1.mn.comcast.net[66.41.141.26]) by comcast.net (sccrmhc14) with SMTP id <2005052218335901400iaobke>; Sun, 22 May 2005 18:33:59 +0000 Message-Id: <5.2.1.1.0.20050522111055.032e9458@pop.shell.visi.com> X-Sender: hoju@pop.shell.visi.com X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Sun, 22 May 2005 13:33:51 -0500 To: "Log4J Users List" From: Jacob Kjome Subject: Re: Multiple Projects Using Same Logger In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N At 12:05 AM 5/22/2005 +0000, you wrote: >Hi, > >>I'm a new log4j user. I want to use it in a j2ee web application--however, >>I want its >>components, packed in separate jars, to use the same logger(s), if >>possible. > >I've since discovered that if Bar uses a non-static, local, logger, things >work as I want. I don't know this is advisable, and shall continue >checking. > >Thus my new logMessage() is: > >private void logMessage(String msg, Level lvl) { > Logger logger = Logger.getLogger(this.getClass().getName()); > if ( logger.isDebugEnabled() > && >Logger.getRootLogger().getAllAppenders().hasMoreElements() ) Ok, well, first of all, you changed your code from before. Now you are getting appenders attached to the root logger, instead of the current local logger. Change one thing at a time. I bet this code would work in your previous case from your first email. I think you are confused. The change of the logger from static to a non-static local variable makes no difference unless you are extending this class, in which case this getClass().getName() could return different names. It wouldn't have to be a local variable, though. An instance variable would work fine in that case. Also, Whether a class was loaded from WEB-INF/classes or a jar in WEB-INF/lib is totally and completely indistinguishable from Log4j's point of view. You either configure Log4j and all classes in the classloader use the same configuration or you don't configure and no classes have a log4j configuration. One or the other, not classes in WEB-INF/classes have configuration but classes in jar in WEB-INF/lib don't. That's quite simply impossible. What matters is logger names. As such, the check makes little to no sense unless you are sometimes using this library in cases where you do not configure Log4j at all. But then why use Log4j in the first place? The whole point is to remove usage of System.out for logging. Well, I guess you have your own requirements, so I won't second guess that this may simply be something you have to support. Looks messy to me, IMHO. > logger.log(lvl, msg); > else > System.out.println("sysout:" + msg ); >} > >The caveat here, I suppose, is that RootLogger will need an appender--even >if a do-nothing one. I did read that there are [edge] cases in which the >configured-ness of non-root loggers does not bubble up to the root logger. >Insight from those who've already been down this path would be much >appreciated. > See my previous email. The isConfigured() utility method from http://wiki.apache.org/logging-log4j/UsefulCode should help you out here. >( Incidentally, to elaborate on a prior post, the reason I use logMessage() >is because I expect to want to log context information as well, and I'd like >NDC push/pop to be isolated to and encapsulated in logMessage ) > Ok, that's actually a valid reason to have a separate message. In the code you posted, there was no reason at all. Jake >Regards, > >--A > >_________________________________________________________________ >Don't just search. Find. Check out the new MSN Search! >http://search.msn.click-url.com/go/onm00200636ave/direct/01/ > > >--------------------------------------------------------------------- >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