Commit 99bf1b12 by huluobin

upload

parent 465dee8e
...@@ -84,43 +84,48 @@ public class LogAspect { ...@@ -84,43 +84,48 @@ public class LogAspect {
*/ */
@Around("point()") @Around("point()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
//开始时间
long begin = System.currentTimeMillis();
//方法环绕proceed结果 //方法环绕proceed结果
Object obj = joinPoint.proceed(); Object obj = joinPoint.proceed();
//结束时间 try {
long end = System.currentTimeMillis(); //开始时间
//时间差 long begin = System.currentTimeMillis();
long timeDiff = (end - begin); //结束时间
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); long end = System.currentTimeMillis();
HttpServletRequest request = attributes.getRequest(); //时间差
long timeDiff = (end - begin);
String uri = request.getRequestURI(); ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
if (timeDiff < 200) {
logger.info("{}:方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE02", uri, timeDiff); String uri = request.getRequestURI();
} else {
logger.warn("{}:方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE31", uri, timeDiff); if (timeDiff < 200) {
} logger.info("{}:方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE02", uri, timeDiff);
} else {
logger.warn("{}:方法性能分析: 执行耗时 {}毫秒," + "\uD83D\uDE31", uri, timeDiff);
Map<String, Object> params = new LinkedHashMap<>(10); }
params.put("uri", request.getRequestURI()); // 获取请求的url
//params.put( "method", request.getMethod() ); // 获取请求的方式
params.put("args", joinPoint.getArgs()); // 请求参数 Map<String, Object> params = new LinkedHashMap<>(10);
//params.put( "className", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() ); // 获取类名和获取类方法 params.put("uri", request.getRequestURI()); // 获取请求的url
params.put("ip", getClientIp(request)); // 获取请求的ip地址 //params.put( "method", request.getMethod() ); // 获取请求的方式
params.put("args", joinPoint.getArgs()); // 请求参数
// 输出格式化后的json字符串 //params.put( "className", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() ); // 获取类名和获取类方法
String paramsJson = JsonUtilByFsJson.beanToJson(params); params.put("ip", getClientIp(request)); // 获取请求的ip地址
if (obj instanceof JsonResult) { // 输出格式化后的json字符串
String paramsJson = JsonUtilByFsJson.beanToJson(params);
//统一异常那里打印堆栈
if (obj instanceof JsonResult) {
//统一异常那里打印堆栈
// if (((JsonResult) obj).getCode() != 200) { // if (((JsonResult) obj).getCode() != 200) {
// logger.error("************************异常开始*******************************"); // logger.error("************************异常开始*******************************");
// logger.error("exception param:{}", paramsJson); // logger.error("exception param:{}", paramsJson);
// } // }
}
} catch (Exception ignore) {
} }
return obj; return obj;
......
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