Return-Path: Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: (qmail 78260 invoked from network); 11 Apr 2009 03:36:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Apr 2009 03:36:57 -0000 Received: (qmail 28157 invoked by uid 500); 11 Apr 2009 03:36:56 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 27945 invoked by uid 500); 11 Apr 2009 03:36:55 -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 27927 invoked by uid 99); 11 Apr 2009 03:36:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Apr 2009 03:36:55 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: 76.96.30.96 is neither permitted nor denied by domain of hoju@visi.com) Received: from [76.96.30.96] (HELO QMTA09.emeryville.ca.mail.comcast.net) (76.96.30.96) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Apr 2009 03:36:46 +0000 Received: from OMTA11.emeryville.ca.mail.comcast.net ([76.96.30.36]) by QMTA09.emeryville.ca.mail.comcast.net with comcast id e2kJ1b0060mlR8UA93cT4z; Sat, 11 Apr 2009 03:36:27 +0000 Received: from [127.0.0.1] ([24.118.113.101]) by OMTA11.emeryville.ca.mail.comcast.net with comcast id e3cR1b0052BKKcw8X3cRXK; Sat, 11 Apr 2009 03:36:26 +0000 Message-ID: <49E01E6A.3070904@visi.com> Date: Fri, 10 Apr 2009 22:36:58 -0600 From: Jacob Kjome User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b1pre) Gecko/20081031 Eudora/3.0a3 MIME-Version: 1.0 To: Log4J Users List Subject: Re: Beginners question: log4j implementation, variable log4j properties References: <22987689.post@talk.nabble.com> In-Reply-To: <22987689.post@talk.nabble.com> X-Enigmail-Version: 0.96a Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Relayed-By: GPGrelay Version 0.959 (Win32) X-Virus-Checked: Checked by ClamAV on apache.org Please don't post user questions to the dev list. I've sent this to the user list, Bcc'ing the dev list, just in case you are not subscribed to the user list yet. See comments below... On 4/10/2009 7:03 AM, mb77 wrote: > Hello everybody, > > Beginners question here, hope all will be clear enough and log4j specific > enough. > > I'm co-building an application that consists of around thirty java classes > that all use log4j. > We have a class called MyLogger.java that is imported by all these classes. > In MyLogger we have this line : > public static final org.apache.log4j.Logger log = > Logger.getLogger("MyLogger.class"); > > We use a log4jproperties file for now ,but the finished application will > take care that every user's log4j properties are read from his/her own > inifile (using PropertyConfigurator). At a certain point in our code we > determine which user we are dealing with , but until that time we would like > to use a default inifile. > > As stated above , the logging object is created like this: > public static final org.apache.log4j.Logger log = > Logger.getLogger(RemLogger.class); > As far as i understand this object is created the first time one of our > classes imports the MyLogger class. > > Would it be possible somehow to tweak this code so that the constructor of > MyLogger is called? No. All that happens when you pass a class into getLogger() is it gets the name of the class by calling Class.getName(). > In the constructor i would place something like this: > URL url = Loader.getResource("default.ini"); > PropertyConfigurator.configure(url); I really don't recommend that. General application code should not perform configuration. Leave that to specialized startup classes. Either place log4j.properties or log4j.xml in the root of the classpath for Log4j auto-configuration or run manual configuration from something like a ServletContextListener or a Main class. You will find nothing but grief by reconfiguring the current logger repository (generally the default one unless you are using repository selector.... which I bet you are not) multiple times as you think you want; once per ever time you call Logger.getLogger(SomeClass.class). You'll end up doubling up appenders, getting duplicate, triplicate, quadruplicate, etc... logging. Remember. It is not really the job of the library developer to decide which stuff gets logged. It is the application deployer (possibly in consulation with developers). Individual libraries my provide information by logging it, but it's the person(s) who read the log that ought to control what actually gets logged. > > Hope i made my question clear and would appreciate any help immensely!! > Thanks in advance, > Mark > > Jake --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.apache.org