From general-return-672-apmail-logging-general-archive=logging.apache.org@logging.apache.org Mon Nov 28 03:42:13 2005 Return-Path: Delivered-To: apmail-logging-general-archive@www.apache.org Received: (qmail 63022 invoked from network); 28 Nov 2005 03:42:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Nov 2005 03:42:13 -0000 Received: (qmail 56728 invoked by uid 500); 28 Nov 2005 03:42:13 -0000 Delivered-To: apmail-logging-general-archive@logging.apache.org Received: (qmail 56674 invoked by uid 500); 28 Nov 2005 03:42:12 -0000 Mailing-List: contact general-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Logging General" List-Id: Delivered-To: mailing list general@logging.apache.org Received: (qmail 56663 invoked by uid 99); 28 Nov 2005 03:42:12 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Nov 2005 19:42:12 -0800 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=NO_DNS_FOR_FROM,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [131.232.10.21] (HELO smtp.athabascau.ca) (131.232.10.21) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Nov 2005 19:43:42 -0800 Received: from CONVERSION-DAEMON.local.athabascau.ca by local.athabascau.ca (PMDF V6.2-1x9 #31075) id <0IQN0QB01BLQ9P@local.athabascau.ca> for general@logging.apache.org; Sun, 27 Nov 2005 20:41:50 -0700 (MST) Received: from [192.168.7.9] ([209.89.243.91]) by local.athabascau.ca (PMDF V6.2-1x9 #31075) with ESMTPSA id <0IQN0Q8D4BLPZX@local.athabascau.ca> for general@logging.apache.org; Sun, 27 Nov 2005 20:41:49 -0700 (MST) Date: Sun, 27 Nov 2005 20:41:40 -0700 From: "Trenton D. Adams" Subject: taking advantage of JDK enhancements To: general@logging.apache.org Message-id: <438A7C74.5030402@athabascau.ca> X-Envelope-from: trenta@athabascau.ca MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.7 (X11/20050923) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi everyone, I'm just curious if you guys think it would be beneficial to provide factories for various objects in the log4j project, so that one could choose to use the new objects, in the event they use a newer version of java. Or, even auto detect the newer version of java, and use them automatically. For instance. I noticed that LocationInfo gets the location information by parsing the output of the strack trace. In java 1.4, there is something called "StackTraceElement", which has all of this information. The throwable object can give this to you. The time it takes is significantly less than log4j's parsing. I did a loop of 1M, logging a simple line of text each time. Printing out the stack trace info, such as line number, took about 0.06ms, whereas it took 0.3ms with log4j. So, it took approximately 60 seconds to run through the whole loop. Not printing it took 30 seconds. Given the extremely high performance of this method of obtaining stack trace info, I use it in all of my logs. :) Here's an example. Logger logger; Throwable th; StackTraceElement[] ste; th = new Throwable(); ste = th.getStackTrace(); if (ste.length == 0) { // no stack trace -- bad logger = AGeneralStatic.logger; } else { int idx = 0; if (ste.length > 2) { idx = 2; } logger = LogManager.getLogger(ste[idx].getClassName() + "." + ste[idx].getMethodName()); } So, instantiating LocationInfo through a factory would definitely be beneficial, as you could simply instantiate different objects based on the JDK that is currently running. Then, all I have to do to get line numbers is add the %L, and wham, I've got them with very high performance. __ This communication is intended for the use of the recipient to whom it is addressed, and may contain confidential, personal, and or privileged information. Please contact us immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communications received in error, or subsequent reply, should be deleted or destroyed. ---