Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 24425 invoked from network); 22 Oct 2009 18:30:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Oct 2009 18:30:24 -0000 Received: (qmail 61773 invoked by uid 500); 22 Oct 2009 18:30:23 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 61666 invoked by uid 500); 22 Oct 2009 18:30:23 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 61656 invoked by uid 99); 22 Oct 2009 18:30:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Oct 2009 18:30:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Oct 2009 18:30:20 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 7AB9D234C48C for ; Thu, 22 Oct 2009 11:29:59 -0700 (PDT) Message-ID: <610314526.1256236199501.JavaMail.jira@brutus> Date: Thu, 22 Oct 2009 18:29:59 +0000 (UTC) From: "Nathan Niesen (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (LOGGING-132) Jdk14Logger wrapper does not respect logger name In-Reply-To: <1940045762.1256235419485.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Nathan Niesen updated LOGGING-132: ---------------------------------- Description: The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library. Example: I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA"). With the other log wrappers, if I log a message I always get something like:
Oct 21, 2009 5:03:26 PM [INFO] SubSystemA start - My log message
With the JDK log wrapper, I get something like:
Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start INFO: My log message
Or worse yet with obfuscated code and the JDK log wrapper, I get something like: Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000 INFO: My log message The fix: In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name. private void log( Level level, String msg, Throwable ex ) { Logger logger = getLogger(); if (logger.isLoggable(level)) { // Hack (?) to get the stack trace. Throwable dummyException=new Throwable(); StackTraceElement locations[]=dummyException.getStackTrace(); // Caller will be the third element String cname="unknown"; String method="unknown"; if( locations!=null && locations.length >2 ) { StackTraceElement caller=locations[2]; cname=caller.getClassName(); method=caller.getMethodName(); } if( ex==null ) { logger.logp( level, cname, method, msg ); } else { logger.logp( level, cname, method, msg, ex ); } } } was: The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. It is also problematic for obfuscated code and private parts of an application or library. Example: I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA"). With the other log wrappers, if I log a message I always get something like: Oct 21, 2009 5:03:26 PM [INFO] SubSystemA start - My log message With the JDK log wrapper, I get something like: Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start INFO: My log message Or worse yet with obfuscated code and the JDK log wrapper, I get something like: Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000 INFO: My log message The fix: In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name. private void log( Level level, String msg, Throwable ex ) { Logger logger = getLogger(); if (logger.isLoggable(level)) { // Hack (?) to get the stack trace. Throwable dummyException=new Throwable(); StackTraceElement locations[]=dummyException.getStackTrace(); // Caller will be the third element String cname="unknown"; String method="unknown"; if( locations!=null && locations.length >2 ) { StackTraceElement caller=locations[2]; cname=caller.getClassName(); method=caller.getMethodName(); } if( ex==null ) { logger.logp( level, cname, method, msg ); } else { logger.logp( level, cname, method, msg, ex ); } } } > Jdk14Logger wrapper does not respect logger name > ------------------------------------------------ > > Key: LOGGING-132 > URL: https://issues.apache.org/jira/browse/LOGGING-132 > Project: Commons Logging > Issue Type: Bug > Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 2.0 > Reporter: Nathan Niesen > Priority: Minor > > The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library. > Example: > I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA"). > With the other log wrappers, if I log a message I always get something like: >
> Oct 21, 2009 5:03:26 PM > [INFO] SubSystemA start - My log message >
> With the JDK log wrapper, I get something like: >
> Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start > INFO: My log message >
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like: > > Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000 > 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000 > 00000000000000000000000000000000000000000000000000000000 > INFO: My log message > > The fix: > In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name. > private void log( Level level, String msg, Throwable ex ) { > Logger logger = getLogger(); > if (logger.isLoggable(level)) { > // Hack (?) to get the stack trace. > Throwable dummyException=new Throwable(); > StackTraceElement locations[]=dummyException.getStackTrace(); > // Caller will be the third element > String cname="unknown"; > String method="unknown"; > if( locations!=null && locations.length >2 ) { > StackTraceElement caller=locations[2]; > cname=caller.getClassName(); > method=caller.getMethodName(); > } > if( ex==null ) { > logger.logp( level, cname, method, msg ); > } else { > logger.logp( level, cname, method, msg, ex ); > } > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.