Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 88509 invoked from network); 8 Aug 2010 12:09:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Aug 2010 12:09:13 -0000 Received: (qmail 15692 invoked by uid 500); 8 Aug 2010 12:09:13 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 15133 invoked by uid 500); 8 Aug 2010 12:09:10 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 15125 invoked by uid 99); 8 Aug 2010 12:09:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Aug 2010 12:09:09 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sebbaz@gmail.com designates 209.85.216.43 as permitted sender) Received: from [209.85.216.43] (HELO mail-qw0-f43.google.com) (209.85.216.43) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Aug 2010 12:09:02 +0000 Received: by qwd6 with SMTP id 6so6295935qwd.30 for ; Sun, 08 Aug 2010 05:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=UseIl8aw3loiDt7fOB2I266r6FSk5ybNjfegq1dQgek=; b=D5NwW9YLrO02gccgHQR0rU/IXooNXbzDR+OgH6Zx+m9nizmj/9j5rN5j14avkwuEHO MmGwsQhwZbfADLNU9Yxg0UnW3bqqiWW0QavAaZiK7uiqHEuFJd80r5bVz79/jTaOpUMb aQCI3fOpCqaJlJKzp3KKPeT9qU66hCJEABJzg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=mpXlv9I5vtk5lG7TUnfak2SGOEganLtKkiUX1Q8Hg90m2DMF6GfJRj4jJymXa1a4NZ 35xJQbumKgTNSSQvBEENERmcnPSLPxkkzYbjP+M6hf1QnxhlLnBgpJsaOfIJdaRZtMZD ZpEBEz/7IdYaRr3Y04uoPfJGfOGI+Nd60HJHU= MIME-Version: 1.0 Received: by 10.220.128.68 with SMTP id j4mr9159173vcs.68.1281269321727; Sun, 08 Aug 2010 05:08:41 -0700 (PDT) Received: by 10.220.161.81 with HTTP; Sun, 8 Aug 2010 05:08:41 -0700 (PDT) In-Reply-To: References: Date: Sun, 8 Aug 2010 13:08:41 +0100 Message-ID: Subject: Re: LogFactory.getLog() From: sebb To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On 7 August 2010 06:00, James Carman wrote: > Attachments don't come through. =A0File a JIRA +1 - please > > On Fri, Aug 6, 2010 at 10:11 PM, Doug Bateman wrot= e: >> Dear Commons Developers, >> >> Here's a suggestion for the commons-logging package... >> >> Presently, in Apache Commons, the most common way to get a logger is to = do >> something like: >> >> public class MyClass { >> =A0=A0=A0 private static Log log =3D LogFactory.getLog(MyClass.class); >> } >> >> Notice how MyClass.class (or alternatively a string name) is passed as a >> parameter.=A0 The annoying aspect of this is that sometimes the class na= me >> doesn't get updated when doing copy/paste operations.=A0 A desirable >> alternative might be: >> >> public class MyClass { >> =A0=A0=A0 private static Log log =3D LogFactory.getLog(); //class name i= nferred from >> call stack >> } >> >> >> With such an approach there are two possible concerns I can foresee: >> >> Call stack inspection isn't terribly fast.=A0 However since Loggers are >> generally initialized only once, when the class is first loaded, perform= ance >> isn't likely to be a major problem. >> Commons-logging is Java 1.1 compatible.=A0 Thus care must be taken to en= sure >> compatibility isn't broken. >> Commons-logging doesn't depend on commons-lang, and thus the utilities i= n >> commons-lang cannot be used. >> >> In Java 1.4, the call stack is easily obtained using Thread.getCallStack= (). Huh? I cannot find that method anywhere. Do you perhaps mean public StackTraceElement[] getStackTrace() which is @since Java 1.5? >> Prior to Java 1.4, the only way to obtain the call stack is to inspect t= he >> stack trace of an exception. >> >> >> I've attached to this email a proof of concept implementation.=A0 It tes= ts >> successfully in Java 1.0+ and Java 1.4+.=A0 In order to ensure the >> implementation doesn't break for Java 1.0, I used reflection to invoke t= he >> Java 1.4 APIs when they are available. >> >> Cheers, >> Doug >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> For additional commands, e-mail: dev-help@commons.apache.org >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org