Return-Path: Delivered-To: apmail-labs-commits-archive@minotaur.apache.org Received: (qmail 49839 invoked from network); 6 Dec 2010 11:06:40 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 6 Dec 2010 11:06:40 -0000 Received: (qmail 9467 invoked by uid 500); 6 Dec 2010 11:06:39 -0000 Delivered-To: apmail-labs-commits-archive@labs.apache.org Received: (qmail 9348 invoked by uid 500); 6 Dec 2010 11:06:37 -0000 Mailing-List: contact commits-help@labs.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: labs@labs.apache.org Delivered-To: mailing list commits@labs.apache.org Received: (qmail 9341 invoked by uid 99); 6 Dec 2010 11:06:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Dec 2010 11:06:36 +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.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Dec 2010 11:06:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 50BA32388A36; Mon, 6 Dec 2010 11:06:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1042578 - in /labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging: LogThreadLocal.java Tracing.aj Date: Mon, 06 Dec 2010 11:06:12 -0000 To: commits@labs.apache.org From: simoneg@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101206110612.50BA32388A36@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: simoneg Date: Mon Dec 6 11:06:11 2010 New Revision: 1042578 URL: http://svn.apache.org/viewvc?rev=1042578&view=rev Log: Rewritten as before/after instead of around to avoid AspectJ bug Modified: labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/LogThreadLocal.java labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/Tracing.aj Modified: labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/LogThreadLocal.java URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/LogThreadLocal.java?rev=1042578&r1=1042577&r2=1042578&view=diff ============================================================================== --- labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/LogThreadLocal.java (original) +++ labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/LogThreadLocal.java Mon Dec 6 11:06:11 2010 @@ -1,5 +1,7 @@ package org.apache.magma.logging; +import java.util.ArrayList; +import java.util.List; import java.util.Stack; public class LogThreadLocal { @@ -13,6 +15,8 @@ public class LogThreadLocal { private long timeIn = 0; private long timeOut = 0; + private ArrayList times = new ArrayList(); + public LogThreadLocal(ThreadLocal mytl) { this.mytl = mytl; } @@ -82,4 +86,21 @@ public class LogThreadLocal { return timeOut; } + private void checkTimeArray() { + this.times.ensureCapacity((int)this.counter + 1); + while (this.times.size() <= this.counter) { + this.times.add(0l); + } + } + + public void pushTime(long t) { + checkTimeArray(); + this.times.set((int)this.counter, t); + } + + public long popTime() { + checkTimeArray(); + return this.times.get((int)this.counter); + } + }; \ No newline at end of file Modified: labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/Tracing.aj URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/Tracing.aj?rev=1042578&r1=1042577&r2=1042578&view=diff ============================================================================== --- labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/Tracing.aj (original) +++ labs/magma/trunk/foundation-logging/src/main/java/org/apache/magma/logging/Tracing.aj Mon Dec 6 11:06:11 2010 @@ -37,11 +37,123 @@ public abstract aspect Tracing { * Must be a call, eventually with other conditions */ public abstract pointcut to(); + + protected void logIn(final JoinPoint tjp, final String enter, final String more) { + final LogThreadLocal ltl = tc.get(); + if (ltl.isInside()) { + return; + } + ltl.entering(); + try { + ltl.sendBuffered(); + } catch (Exception e) {} + ltl.increment(); + try { + final Signature sig = tjp.getSignature(); + Object th = tjp.getThis(); + Class c = null; + if (th != null) { + c = th.getClass(); + } else { + c = tjp.getSignature().getDeclaringType(); + } + final Logger l = LoggerFactory.getLogger(c); + final Object[] args = tjp.getArgs(); + LogClosure logcl = new LogClosure() { + @Override + public void doLog() { + if (args != null && args.length > 0) { + l.debug(">{} {} {}({}) [{}] "+more, new Object[] {ltl.getCounter(), enter, sig.toShortString(), args, tjp.getSourceLocation()}); + } else { + l.debug(">{} {} {} [{}] "+more, new Object[] {ltl.getCounter(), enter, sig.toShortString(), tjp.getSourceLocation()}); + } + } + }; + ltl.setBuffered(logcl); + ltl.pushTime(ltl.getTimeOut()); + } finally { + ltl.exiting(); + } + } + + protected void logOut(final JoinPoint tjp, Object ret, String exit, String compress, final String more) { + final LogThreadLocal ltl = tc.get(); + if (ltl.isInside()) { + return; + } + ltl.entering(); + try { + final Signature sig = tjp.getSignature(); + Object th = tjp.getThis(); + Class c = null; + if (th != null) { + c = th.getClass(); + } else { + c = tjp.getSignature().getDeclaringType(); + } + final Logger l = LoggerFactory.getLogger(c); + final Object[] args = tjp.getArgs(); + double et = ltl.getTimeOut() - ltl.popTime(); + et = et / 1000000; + if (ltl.getBuffered() == null) { + l.debug("<{} {} {}({}) took {}ms returned {}", new Object[] {ltl.getCounter(), exit, sig.toShortString(), args, new Double(et), ret}); + } else { + ltl.setBuffered(null); + l.debug("){} {} {}({}) [{}] took {}ms returned {} "+more, new Object[] {ltl.getCounter(), compress, sig.toShortString(), args, tjp.getSourceLocation(), new Double(et), ret}); + } + if (ltl.getCounter() == 1) { + l.debug("Logger used {} on {} total nanos", ltl.getTimeIn(), ltl.getTimeOut()); + } + } finally { + ltl.decrement(); + ltl.exiting(); + } + } - private interface Closure { - Object doProceed(); + protected void logException(final JoinPoint tjp, Throwable t) { + final LogThreadLocal ltl = tc.get(); + if (ltl.isInside()) return; + if (ltl.getLastException() == t) return; + ltl.entering(); + try { + ltl.setLastException(t); + Signature sig = tjp.getSignature(); + Object th = tjp.getThis(); + Class c = null; + if (th != null) { + c = th.getClass(); + } else { + c = tjp.getSignature().getDeclaringType(); + } + Logger l = LoggerFactory.getLogger(c); + Object[] args = tjp.getArgs(); + l.warn("