Return-Path: Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: (qmail 81795 invoked from network); 21 May 2005 20:17:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 May 2005 20:17:29 -0000 Received: (qmail 98540 invoked by uid 500); 21 May 2005 20:17:22 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 98493 invoked by uid 500); 21 May 2005 20:17:21 -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 98477 invoked by uid 99); 21 May 2005 20:17:21 -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.55 is neither permitted nor denied by domain of hoju@visi.com) Received: from sccrmhc11.comcast.net (HELO sccrmhc11.comcast.net) (204.127.202.55) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 21 May 2005 13:17:20 -0700 Received: from nicki.visi.com (c-66-41-141-26.hsd1.mn.comcast.net[66.41.141.26]) by comcast.net (sccrmhc11) with SMTP id <2005052120171501100op2k3e>; Sat, 21 May 2005 20:17:15 +0000 Message-Id: <5.2.1.1.0.20050521150452.032d7438@pop.shell.visi.com> X-Sender: hoju@pop.shell.visi.com X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Sat, 21 May 2005 15:17:11 -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 classes in jars that are put in WEB-INF/lib are run in exactly the same classloader as those in WEB-INF/classes. You need not do all the checking of appenders and such. In fact, you are probably making bad assumptions on behavior which is why you only ever see the System.out message. Simply do... logger.info("log message"); No need to have the extra logMessage() method either. You are hardcoding Level.INFO, so why not just use logger.info() directly in getBar()? If you see no output from this, then you haven't configured things properly. However, based on your configuration below, any class in com.foo should log to info or higher severity and any class in com.bar should log to debug or higher severity. Classes not in those packages (and are not children of those packages) will log to error or higher severity. All logging should go to the console appender which has been added to the root logger which all other loggers will inherit from. BTW, are you doing anything special in your InitServlet? If not, just let autoconfiguration work for you. It will find log4j.properties and perform configuration in a static initializer by default. No need to do this manually unless you are doing something special. You are really over engineering this. KISS. Jake At 04:48 PM 5/21/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. My configuration is shown below: > >j2ee web app >======= > webroot/ > WEB-INF/ > classes/ > log4jInitServlet (uses log4j props file) > log4j.properties > com.foo/ (classes in this package use logger) > >So far so good. I'm able to initialize a logger, and to log from any of the >classes in "classes/". > >Now, I want to use this already-initialized logger to log from classes >deployed in jar files in WEB-INF/lib/ . Is this possible? Thus far my >attempts have been unsuccessful. > >For example, I have a separate java project, whose classes reside in package >"com.bar", and which have been jar-ed and placed in WEB-INF/lib. One of >those classes is something like this: > >package com.bar; > >import org.apache.log4j.*; > >class Bar { > static Logger logger = Logger.getLogger(Bar.class.getName()); > > public void getBar() { > logMessage( "called getBar", Level.INFO); > } > > private void logMessage(String msg, Level lvl) { > if ( logger != null && logger.getAllAppenders().hasMoreElements() ) > logger.log(lvl, msg); > else > System.out.println("sysout:" + msg + " : " + lvl.toString()); > } >} > >The idea is that Bar provides some functionality to the webapp, and I want >calls to it logged. Again, though, I'd like Bar's logging to use the same >logger(s) already-initialised by the webapp. My props file is as below: > >log4j.rootLogger=ERROR, A1 >log4j.appender.A1=org.apache.log4j.ConsoleAppender >log4j.appender.A1.layout=org.apache.log4j.PatternLayout > ># Set levels >log4j.logger.com.foo=INFO >log4j.logger.com.bar=DEBUG > >However, all log output from bar says "sysout", meaning it isn't using the >logger. I suspect this may be classloader related, but am unsure. > >Would somebody enlighten me, please? > >(I did search the web, and will continue to do so -- but have not yet come >across anything germane.) > >Regards, > >--A > >_________________________________________________________________ >Express yourself instantly with MSN Messenger! Download today - it's FREE! >http://messenger.msn.click-url.com/go/onm00200471ave/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