logging - Getting line number from the joinPoint -
i trying access line number (for logging purpose) joinpoint sourcelocation in around advice. giving
exception in thread "main" java.lang.unsupportedoperationexception @ org.springframework.aop.aspectj.methodinvocationproceedingjoinpoint$sourcelocationimpl.getline(methodinvocationproceedingjoinpoint.java:282) i getting null loc.getline() on debugging.
@around("execution (* com.logger.rms.*.*(..))") public void logaround(proceedingjoinpoint procjoinpoint) throws throwable { staticpart part = (procjoinpoint.getstaticpart()); org.aspectj.lang.reflect.sourcelocation loc = part.getsourcelocation(); int line = loc.getline(); system.out.println(line); try { procjoinpoint.proceed(); } catch (throwable e) { system.out.println("checking " +procjoinpoint.getsourcelocation().getwithintype().getcanonicalname()); string str="aspect concretetester :"+ procjoinpoint.getstaticpart().getsourcelocation().getline() ; throw new businesslogicexception("throwing custom business exception around"); }finally{ } } }
use
procjoinpoint.getsourcelocation().getline()
@around("execution (* com.logger.rms.*.*(..))") public object logaround(proceedingjoinpoint procjoinpoint) throws throwable { int line= procjoinpoint.getsourcelocation().getline(); system.out.println(line); system.out.println("in around before " + procjoinpoint ); object result=null; try { result = procjoinpoint.proceed(); } catch (throwable e) { throw new businesslogicexception("throwing custom business exception around"); }finally{ } system.out.println("in around after " + procjoinpoint+ " wtirh result " + result); return result }
Comments
Post a Comment