EalenXie / aop-log

项目正式命名为aop-log,基于Spring AOP,ThreadLocal实现方法埋点信息收集与处理。
Apache License 2.0
117 stars 54 forks source link

多层调用有bug #6

Closed arccode closed 4 years ago

arccode commented 4 years ago

调用链: ServiceA -> ServiceB -> ServiceC

@AopLog(type = "ServiceA", stackTraceOnErr = true) @Service public class ServiceA implements IServiceA {

@Resource private IServiceB serviceB;

public void execute() {

LogData.step("A-Begin"); ... serviceB.execute(); LogData.step("A-End");

} }

@AopLog(type = "ServiceB", stackTraceOnErr = true) @Service public class ServiceB implements IServiceB {

@Resource private IServiceC serviceC;

public void execute() {

LogData.step("B-Begin"); ... serviceC.execute(); LogData.step("B-End");

} }

@AopLog(type = "ServiceC", stackTraceOnErr = true) @Service public class ServiceC implements IServiceC {

LogData.step("C-Begin"); ... LogData.step("C-End"); }

结果:

日志 B-End、C-End丢失

EalenXie commented 4 years ago

只需要再A上面加AopLog即可。不需要每个类上都打,还是说的你场景是所有类的所有参数都需要拦截?

EalenXie commented 4 years ago

只要LogData.step在被@AopLog拦截的整体方法链路内(包括此方法调用的其他外部方法内)被调用,都是有效的。再者这样每个方法都做切面拦截,对效率是有所影响的。