Spring Aop logging line number incorrect -
Spring Aop logging line number incorrect -
i using spring aop logging application : have before after , afterthrowing advice configured line numbers see not of target class of class used logging how can solve below configuration
spring xml :
<aop:aspectj-autoproxy proxy-target-class="false" />
class used logging :
package com.digilegal.services.ahc.logging; import java.lang.reflect.modifier; import org.apache.log4j.logger; import org.aspectj.lang.joinpoint; import org.aspectj.lang.annotation.after; import org.aspectj.lang.annotation.afterthrowing; import org.aspectj.lang.annotation.aspect; import org.aspectj.lang.annotation.before; import org.aspectj.lang.reflect.methodsignature; import org.springframework.core.ordered; import org.springframework.core.annotation.order; @aspect public class ahclogging { @before("execution(* com.digilegal.services..*.*(..))") public void logbefore(joinpoint joinpoint) { logger log = logger.getlogger(joinpoint.gettarget().getclass()); methodsignature signature = (methodsignature) joinpoint.getsignature(); if (!modifier.isprivate(signature.getmodifiers()) && !signature.getname().startswith("get") && !signature.getname().startswith("set") && !signature.getname().startswith("is")) { log.trace("enter method ::" + signature.getreturntype().getsimplename() + " " + signature.getname() + "(" + paramtertype(signature.getparametertypes()) + ")"); } } @after("execution(* com.digilegal.services..*.*(..))") public void logafter(joinpoint joinpoint) { logger log = logger.getlogger(joinpoint.gettarget().getclass()); methodsignature signature = (methodsignature) joinpoint.getsignature(); if (!modifier.isprivate(signature.getmodifiers()) && !signature.getname().startswith("get") && !signature.getname().startswith("set") && !signature.getname().startswith("is")) { log.trace("exit method ::" + signature.getreturntype().getsimplename() + " " + signature.getname() + "(" + paramtertype(signature.getparametertypes()) + ")"); } } @afterthrowing(pointcut = "execution(* com.digilegal.services..*.* (..))",throwing= "error") public void logafterthrowing(joinpoint joinpoint, throwable error) { logger log = logger.getlogger(joinpoint.gettarget().getclass()); methodsignature signature = (methodsignature) joinpoint.getsignature(); if (!modifier.isprivate(signature.getmodifiers()) && !signature.getname().startswith("get") && !signature.getname().startswith("set") && !signature.getname().startswith("is")) { log.error("exception in method ::" + signature.getreturntype().getsimplename() + " " + signature.getname() + "(" + paramtertype(signature.getparametertypes()) + ")"); log.error("exception",error); } } private string paramtertype(class<?>[] classes) { stringbuffer buffer = new stringbuffer(); string returnvalue = ""; (class<?> string : classes) { buffer.append(modifier.tostring(string.getmodifiers())); buffer.append(" "); buffer.append(string.getsimplename()); buffer.append(","); } returnvalue = buffer.tostring(); if (returnvalue.trim().length() > 0) { returnvalue = returnvalue.substring(0, returnvalue.length() - 1); } homecoming returnvalue; } }
am missing or suppose this
thanks
nirav
i think not spring aop problem way log4j works, see javadoc patternlayout:
l
used output line number from logging request issued.
warning generating caller location info extremely slow , should avoided unless execution speed not issue.
so recommendation utilize pattern layout without line number , utilize spring aop's capability of determining line numbers, this:
class="lang-java prettyprint-override">joinpoint.getsourcelocation().getline()
spring logging aop
Comments
Post a Comment