LogAspect.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //package com.imed.costaccount.common.aop;
  2. //
  3. //import cn.hutool.core.net.NetUtil;
  4. //import cn.hutool.json.JSONUtil;
  5. //import com.imed.costaccount.common.util.Result;
  6. //import io.swagger.annotations.ApiOperation;
  7. //import lombok.extern.slf4j.Slf4j;
  8. //import org.aspectj.lang.JoinPoint;
  9. //import org.aspectj.lang.Signature;
  10. //import org.aspectj.lang.annotation.AfterReturning;
  11. //import org.aspectj.lang.annotation.Aspect;
  12. //import org.aspectj.lang.annotation.Before;
  13. //import org.aspectj.lang.annotation.Pointcut;
  14. //import org.aspectj.lang.reflect.MethodSignature;
  15. //import org.springframework.stereotype.Component;
  16. //import org.springframework.web.context.request.RequestContextHolder;
  17. //import org.springframework.web.context.request.ServletRequestAttributes;
  18. //
  19. //import javax.servlet.http.HttpServletRequest;
  20. //
  21. //@Aspect
  22. //@Slf4j
  23. //@Component
  24. //public class LogAspect {
  25. //
  26. // /**
  27. // * ..表示包及子包 该方法代表controller层的所有方法
  28. // */
  29. // @Pointcut("execution(public * com.imed.costaccount.web.*.*(..))")
  30. // public void controllerMethod() {
  31. // }
  32. //
  33. //
  34. // /**
  35. // * 方法执行前
  36. // *
  37. // * @param joinPoint
  38. // * @throws Exception
  39. // */
  40. // @Before("controllerMethod()")
  41. // public void LogRequestInfo(JoinPoint joinPoint) throws Exception {
  42. //
  43. // ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  44. // HttpServletRequest request = attributes.getRequest();
  45. //
  46. // StringBuilder requestLog = new StringBuilder();
  47. // Signature signature = joinPoint.getSignature();
  48. // requestLog.append(((MethodSignature) signature).getMethod().getAnnotation(ApiOperation.class).value()).append("\t")
  49. // .append("请求信息:").append("URL = {").append(request.getRequestURI()).append("},\t")
  50. // .append("请求方式 = {").append(request.getMethod()).append("},\t")
  51. // .append("请求IP = {").append(NetUtil.getLocalhostStr()).append("},\t")
  52. // .append("类方法 = {").append(signature.getDeclaringTypeName()).append(".")
  53. // .append(signature.getName()).append("},\t");
  54. //
  55. // // 处理请求参数
  56. // String[] paramNames = ((MethodSignature) signature).getParameterNames();
  57. // Object[] paramValues = joinPoint.getArgs();
  58. // int paramLength = null == paramNames ? 0 : paramNames.length;
  59. // if (paramLength == 0) {
  60. // requestLog.append("请求参数 = {} ");
  61. // } else {
  62. // requestLog.append("请求参数 = [");
  63. // for (int i = 0; i < paramLength - 1; i++) {
  64. // requestLog.append(paramNames[i]).append("=").append(JSONUtil.toJsonStr(paramValues[i])).append(",");
  65. // }
  66. // requestLog.append(paramNames[paramLength - 1]).append("=").append(JSONUtil.toJsonStr(paramValues[paramLength - 1])).append("]");
  67. // }
  68. //
  69. // log.info(requestLog.toString());
  70. // }
  71. //
  72. //
  73. // /**
  74. // * 方法执行后
  75. // *
  76. // * @param result
  77. // * @throws Exception
  78. // */
  79. // @AfterReturning(returning = "result", pointcut = "controllerMethod()")
  80. // public void logResultVOInfo(Result result) throws Exception {
  81. // log.info("请求结果:" + result.getStatus() + "\t" + result.getMsg());
  82. // }
  83. //
  84. //}