|
|
|
@ -1,30 +1,30 @@ |
|
|
|
package com.elink.esua.epdc.modules.item.aspect; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import org.aspectj.lang.JoinPoint; |
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
import org.aspectj.lang.annotation.*; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
@Component |
|
|
|
@Aspect |
|
|
|
public class RequestLogAspect { |
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(RequestLogAspect.class); |
|
|
|
|
|
|
|
/** |
|
|
|
* 切入点 |
|
|
|
*/ |
|
|
|
@Pointcut("execution(* com.elink.esua.epdc.modules.item.controller..*(..)) ") |
|
|
|
public void entryPoint() { |
|
|
|
// 无需内容
|
|
|
|
} |
|
|
|
//package com.elink.esua.epdc.modules.item.aspect;
|
|
|
|
//
|
|
|
|
//import com.alibaba.fastjson.JSON;
|
|
|
|
//import org.aspectj.lang.JoinPoint;
|
|
|
|
//import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
|
//import org.aspectj.lang.annotation.*;
|
|
|
|
//import org.slf4j.Logger;
|
|
|
|
//import org.slf4j.LoggerFactory;
|
|
|
|
//import org.springframework.stereotype.Component;
|
|
|
|
//import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
//import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
//
|
|
|
|
//import javax.servlet.http.HttpServletRequest;
|
|
|
|
//
|
|
|
|
//@Component
|
|
|
|
//@Aspect
|
|
|
|
//public class RequestLogAspect {
|
|
|
|
//
|
|
|
|
// private static final Logger log = LoggerFactory.getLogger(RequestLogAspect.class);
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * 切入点
|
|
|
|
// */
|
|
|
|
// @Pointcut("execution(* com.elink.esua.epdc.modules.item.controller..*(..)) ")
|
|
|
|
// public void entryPoint() {
|
|
|
|
// // 无需内容
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Before("entryPoint()")
|
|
|
|
// public void doBefore(JoinPoint joinPoint) {
|
|
|
|
@ -70,21 +70,21 @@ public class RequestLogAspect { |
|
|
|
//
|
|
|
|
// return result;
|
|
|
|
// }
|
|
|
|
|
|
|
|
@AfterThrowing(pointcut = "entryPoint()", throwing = "e") |
|
|
|
public void doAfterThrowing(JoinPoint joinPoint, Throwable e) { |
|
|
|
// 通过request获取登陆用户信息
|
|
|
|
// HttpServletRequest request = ((ServletRequestAttributes)
|
|
|
|
// RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
|
try { |
|
|
|
String className = joinPoint.getTarget().getClass().getName(); |
|
|
|
String methodName = joinPoint.getSignature().getName(); |
|
|
|
Object[] parameters = joinPoint.getArgs(); |
|
|
|
|
|
|
|
log.info("异常方法:" + className + "." + methodName + "();参数:" + JSON.toJSONString(parameters)); |
|
|
|
log.info("异常信息:" + e.getMessage()); |
|
|
|
} catch (Exception ex) { |
|
|
|
log.error("异常信息:{}", ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//
|
|
|
|
// @AfterThrowing(pointcut = "entryPoint()", throwing = "e")
|
|
|
|
// public void doAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
|
|
|
// // 通过request获取登陆用户信息
|
|
|
|
// // HttpServletRequest request = ((ServletRequestAttributes)
|
|
|
|
// // RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
|
// try {
|
|
|
|
// String className = joinPoint.getTarget().getClass().getName();
|
|
|
|
// String methodName = joinPoint.getSignature().getName();
|
|
|
|
// Object[] parameters = joinPoint.getArgs();
|
|
|
|
//
|
|
|
|
// log.info("异常方法:" + className + "." + methodName + "();参数:" + JSON.toJSONString(parameters));
|
|
|
|
// log.info("异常信息:" + e.getMessage());
|
|
|
|
// } catch (Exception ex) {
|
|
|
|
// log.error("异常信息:{}", ex.getMessage());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|