首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在java类中使用logback实现特定类和方法的不同记录器模式?

如何在java类中使用logback实现特定类和方法的不同记录器模式?
EN

Stack Overflow用户
提问于 2017-09-20 13:22:05
回答 1查看 1.2K关注 0票数 0

基本aop码

代码语言:javascript
复制
@Aspect
public class LoggingAspect {
private   Logger logger  ;

@Before("execution(*  *(..)) && !execution(* com.*model*.*(..))")
public void logBefore(JoinPoint joinPoint) {
    logger = LoggerFactory.getLogger(joinPoint.getTarget().getClass());
    logger.info("{} :" + joinPoint.getSignature().getName(),"info for user log" );
    //logger.info("hijacked target class : " + joinPoint.getTarget().getClass().getSimpleName() );
}

@After("execution(*  *(..)) && !execution(* com.*model*.*(..)) ")
public void logAfter(JoinPoint joinPoint) {

    System.out.println("logAfter() is running!");
    System.out.println("hijacked : " + joinPoint.getSignature().getName());
    System.out.println("******");

}
}

目前,我正在为某些方法实现aop日志记录,默认情况下,例如方法启动和方法结束.so,使用aop记录器打印apo类和方法,而不是打印方法拥有的类和方法。我必须覆盖aop中的类名来打印该方法的类名,所以我需要将方法名称作为本机方法名

目前我正在

2017-09-20 18:32:06 INFO主c.m.customer.bo.impl.CustomerBoImpl - logBefore : info for user log() :addCustomer

我需要的是

2017-09-20 18:32:06 INFO主c.m.customer.bo.impl.CustomerBoImpl - addCustomer : info for user log() :addCustomer

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-25 20:41:46

最后,我从这个链接ProceedingJoinPoint找到了一个简单的Log4j and AOP, how to get actual class name解决方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46323244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档