当前位置:网站首页>切面打印调取的方法
切面打印调取的方法
2022-08-01 23:22:00 【枫林残@】
@Aspect
@Component
@Slf4j
public class SysLoggerAspect {
@Pointcut("execution(* com.siact..controller..*.*(..))")
public void loggerPointCut() {
}
@Before("loggerPointCut()")
public void saveSysLog(JoinPoint joinPoint) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//请求的方法名
String className = joinPoint.getTarget().getClass().getName();
String methodName = signature.getName();
//请求的参数
Object[] args = joinPoint.getArgs();
StringBuilder params = new StringBuilder();
for(Object o:args){
if(o instanceof HttpServletRequest || o instanceof HttpServletResponse || o instanceof MultipartFile){
continue;
}
params.append("/");
params.append(JSON.toJSONString(o));
}
//获取IP地址
String ip = HttpUtils.getIpAddress();
if(!methodName.contains("login")){
log.info("请求类名>>>:{},请求方法名>>>:{},请求ip:{},请求参数>>>:{}",className,methodName,ip,params);
}
}
@Around("loggerPointCut()")
public Object printElapseTime(ProceedingJoinPoint joinPoint){
long startTime = System.currentTimeMillis();// 开始时间
Object result = null;
try {
result = joinPoint.proceed();
} catch (CustomizeException ex){
log.error(SecurityError.SEC_20005.getLogMsg());
result = new ResponseEntity<>(new ResultInfo<String>().error(SecurityError.SEC_20005), HttpStatus.UNAUTHORIZED);
} catch (Throwable e) {
log.error(ExceptionUtils.getStackTrace(e));
log.error(SystemError.SYS_10019.getLogMsg()) ;
} finally {
long handleTime = System.currentTimeMillis()-startTime;
log.info("请求类名>>>:{},请求方法名>>>:{},请求耗时>>>:{}ms",joinPoint.getTarget().getClass().getName(),((MethodSignature) joinPoint.getSignature()).getName(),handleTime);
}
return result;
}
}
边栏推荐
- 部门项目源码分享
- Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历
- 6134. 找到离给定两个节点最近的节点-力扣双百代码
- How do programmers solve online problems gracefully?
- excel remove all carriage return from a cell
- System availability: 3 9s, 4 9s in SRE's mouth... What is it?
- From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program
- Calculate the midpoint between two points
- sys_kill system call
- When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
猜你喜欢
随机推荐
System availability: 3 9s, 4 9s in SRE's mouth... What is it?
When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
Chapter 19 Tips and Traps: Common Goofs for Novices
数据库表设计规则
仿牛客网项目第三章:开发社区核心功能(详细步骤和思路)
cmd command
[Recommended books] The first self-driving technology book
Quarantine and downgrade
颜色透明参数
请问什么是 CICD
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
萍不回答
论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
numpy.around
牛客多校4 A.Task Computing 思维
vscode hide menu bar
解决端口占用
如何更好的理解的和做好工作?
excel edit a cell without double clicking
分享10套开源免费的高品质源码,免费源码下载平台