我有一个场景,由于公共点切割表达式,我在单个关节点上应用了多个建议。有没有什么办法可以记录当前正在执行或正在执行哪些建议而不给它们不同的日志语句(通过一些方法调用)?
/*
* Advice to check Asset Service 1 response
*/
@Around(value="@annotation(vs2a) && args(mfa)")
public MessageFlowAggregator checkAsset1Response(ProceedingJoinPoint joinPoint,ValidateStage2Advice vs2a,MessageFlowAggregator mfa) throws Throwable {
log.debug(">>> matching advice on {}",joinPoint);
if(mfa!=null){
mfa= (MessageFlowAggregator) joinPoint.proceed();
log.debug("<<< returning advice on {}",joinPoint);
}else{
log.debug("<<< failing advice on {}",joinPoint);
}
return mfa;
}
/*
* Advice to check Customer Service 2 response
*/
@Around(value="@annotation(vs2a) && args(mfa)")
public MessageFlowAggregator checkCustomer2Response(ProceedingJoinPoint joinPoint,ValidateStage2Advice vs2a,MessageFlowAggregator mfa) throws Throwable {
log.debug(">>> matching advice on {}",joinPoint);
if(mfa!=null){
mfa= (MessageFlowAggregator) joinPoint.proceed();
log.debug("<<< returning advice on {}",joinPoint);
}else{
log.debug("<<< failing advice on {}",joinPoint);
}
return mfa;
}
以上建议都打印相同的日志语句,我无法区分它们。
提前致谢!
答案 0 :(得分:0)
好吧,你可以为每条日志消息添加一个前缀。替代方案是:
log.debug("Executing advice: " + new Exception().getStackTrace()[0])
当然,如果你在一个建议中打印两次相同的东西,你应该先将它存储在一个变量中,以免创建异常对象和堆栈跟踪更加昂贵。但我认为调试应该没问题。
答案 1 :(得分:0)
我认为我们使用日志框架日志模式来获取每个打印日志中的方法名称会更好。我更新日志记录模式以在日志中获得所需的输出。
模式:
logging.pattern.console=%d %-5level %t %logger{2}.%M : %msg%n
日志打印为:
2018-02-01 19:17:39,798 INFO main o.s.w.s.s.SaajSoapMessageFactory.afterPropertiesSet : Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
2018-02-01 19:17:39,798 INFO main o.s.w.s.s.SaajSoapMessageFactory.afterPropertiesSet : Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
2018-02-01 19:17:39,798 INFO main o.s.w.s.s.SaajSoapMessageFactory.afterPropertiesSet : Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
2018-02-01 19:17:39,798 INFO main o.s.w.s.s.SaajSoapMessageFactory.afterPropertiesSet : Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol