Commit e1960b74 by huluobin

fix

parent 3e0a8c53
//package com.gogirl.infrastructure.interceptor; package com.gogirl.infrastructure.interceptor;
//
//import com.gogirl.infrastructure.common.util.JsonUtilByFsJson; import com.gogirl.infrastructure.common.util.JsonUtilByFsJson;
//import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
//import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.*; import org.aspectj.lang.annotation.*;
//import org.slf4j.Logger; import org.slf4j.Logger;
//import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
//import java.util.LinkedHashMap; import java.util.LinkedHashMap;
//import java.util.Map; import java.util.Map;
//
///** /**
// * @Description:日志切面 * @Description:日志切面
// * @Author:Kevin * @Author:Kevin
// * @Date:2018-12-07 15:09 * @Date:2018-12-07 15:09
// */ */
////@Profile({"dev", "test"}) //@Profile({"dev", "test"})
//@Component @Component
//@Aspect @Aspect
//public class LogAspect { public class LogAspect {
//
// private final Logger logger = LoggerFactory.getLogger(LogAspect.class); private final Logger logger = LoggerFactory.getLogger(LogAspect.class);
//
// /** /**
// * 定义一个公共的方法,实现切入点 * 定义一个公共的方法,实现切入点
// * 拦截Controller下面的所有方法 任何参数(..表示拦截任何参数) * 拦截Controller下面的所有方法 任何参数(..表示拦截任何参数)
// * 以@RestController注解作为切入点 可切入其他业务模块的方法 * 以@RestController注解作为切入点 可切入其他业务模块的方法
// * *
// * @within和@target针对类的注解, * @within和@target针对类的注解,
// * @annotation是针对方法的注解,为自定义注解 * @annotation是针对方法的注解,为自定义注解
// */ */
//// @Pointcut("execution(public * com.*.web..*.*(..))") // @Pointcut("execution(public * com.*.web..*.*(..))")
// @Pointcut("@within(org.springframework.web.bind.annotation.RestController)") @Pointcut("@within(org.springframework.web.bind.annotation.RestController)")
// public void point() { public void point() {
//
// } }
//
// /** /**
// * 拦截方法之前的一段业务逻辑 * 拦截方法之前的一段业务逻辑
// * *
// * @param joinPoint * @param joinPoint
// */ */
// @Before("point()") @Before("point()")
// public void doBefore(JoinPoint joinPoint) { public void doBefore(JoinPoint joinPoint) {
// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// HttpServletRequest request = attributes.getRequest(); HttpServletRequest request = attributes.getRequest();
//
// Map<String, Object> params = new LinkedHashMap<>(10); Map<String, Object> params = new LinkedHashMap<>(10);
// params.put("uri", request.getRequestURI()); // 获取请求的url params.put("uri", request.getRequestURI()); // 获取请求的url
// //params.put( "method", request.getMethod() ); // 获取请求的方式 //params.put( "method", request.getMethod() ); // 获取请求的方式
// params.put("args", joinPoint.getArgs()); // 请求参数 params.put("args", joinPoint.getArgs()); // 请求参数
// //params.put( "className", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() ); // 获取类名和获取类方法 //params.put( "className", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() ); // 获取类名和获取类方法
// params.put("ip", getClientIp(request)); // 获取请求的ip地址 params.put("ip", getClientIp(request)); // 获取请求的ip地址
//
// // 输出格式化后的json字符串 // 输出格式化后的json字符串
// //logger.info( "params:{}", JSON.toJSONString( params ) ); //logger.info( "params:{}", JSON.toJSONString( params ) );
// //logger.info( "params:{}", JSON.toJSONString( params.get( "args" ) ) ); //logger.info( "params:{}", JSON.toJSONString( params.get( "args" ) ) );
// logger.info("params:{}", JsonUtilByFsJson.beanToJson(params)); logger.info("params:{}", JsonUtilByFsJson.beanToJson(params));
//
// } }
//
// /** /**
// * 获取响应返回值 方法执行return之后 * 获取响应返回值 方法执行return之后
// */ */
// @AfterReturning(returning = "object", pointcut = "point()") @AfterReturning(returning = "object", pointcut = "point()")
// public void doAfterReturning(Object object) { public void doAfterReturning(Object object) {
// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// HttpServletRequest request = attributes.getRequest(); HttpServletRequest request = attributes.getRequest();
// // 会打印出一个对象,想打印出具体内容需要在定义模型处加上toString() // 会打印出一个对象,想打印出具体内容需要在定义模型处加上toString()
// //logger.info( "result:{}", object.toString() ); //logger.info( "result:{}", object.toString() );
// logger.info("result:{}", JsonUtilByFsJson.beanToJson(object)); // logger.info("result:{}", JsonUtilByFsJson.beanToJson(object));
// ; ;
// } }
//
// /** /**
// * 环绕通知 在方法的调用前、后执行 * 环绕通知 在方法的调用前、后执行
// */ */
// @Around("point()") @Around("point()")
// public Object doAround(ProceedingJoinPoint point) throws Throwable { public Object doAround(ProceedingJoinPoint point) throws Throwable {
// //开始时间 //开始时间
// long begin = System.currentTimeMillis(); long begin = System.currentTimeMillis();
// //方法环绕proceed结果 //方法环绕proceed结果
// Object obj = point.proceed(); Object obj = point.proceed();
// //结束时间 //结束时间
// long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
// //时间差 //时间差
// long timeDiff = (end - begin); long timeDiff = (end - begin);
// String msg = "方法性能分析: 执行耗时 {}毫秒,来自Dream PWJ的表情"; String msg = "方法性能分析: 执行耗时 {}毫秒,来自Dream PWJ的表情";
// if (timeDiff < 200) { if (timeDiff < 200) {
// logger.info("方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE02", timeDiff); logger.info("方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE02", timeDiff);
// } else { } else {
// logger.warn("方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE31", timeDiff); logger.warn("方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE31", timeDiff);
// } }
// return obj; return obj;
// } }
//
//
// /** /**
// * 拦截方法之后的一段业务逻辑 * 拦截方法之后的一段业务逻辑
// */ */
// @After("point()") @After("point()")
// public void doAfter() { public void doAfter() {
//// logger.info( "doAfter" ); // logger.info( "doAfter" );
// } }
//
// public String getClientIp(HttpServletRequest request) { public String getClientIp(HttpServletRequest request) {
// String ip = request.getHeader("x-forwarded-for"); String ip = request.getHeader("x-forwarded-for");
// logger.debug("x-forwarded-for = {}", ip); logger.debug("x-forwarded-for = {}", ip);
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
// ip = request.getHeader("Proxy-Client-IP"); ip = request.getHeader("Proxy-Client-IP");
// logger.debug("Proxy-Client-IP = {}", ip); logger.debug("Proxy-Client-IP = {}", ip);
// } }
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
// ip = request.getHeader("WL-Proxy-Client-IP"); ip = request.getHeader("WL-Proxy-Client-IP");
// logger.debug("WL-Proxy-Client-IP = {}", ip); logger.debug("WL-Proxy-Client-IP = {}", ip);
// } }
// if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
// ip = request.getRemoteAddr(); ip = request.getRemoteAddr();
// logger.debug("RemoteAddr-IP = {}", ip); logger.debug("RemoteAddr-IP = {}", ip);
// } }
// if (StringUtils.isNotBlank(ip)) { if (StringUtils.isNotBlank(ip)) {
// ip = ip.split(",")[0]; ip = ip.split(",")[0];
// } }
// return ip; return ip;
// } }
//
//} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment