当前位置:网站首页>切面打印调取的方法
切面打印调取的方法
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;
}
}边栏推荐
- 【数据分析03】
- [LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环
- 高效工作文档产出归类
- 怎样做才能让这条SQL变成一条危险的SQL?
- Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
- Avoid , ,
, and tags - vscode hide menu bar
- PostgreSQL Basics--Common Commands
- When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
- LocalDateTime转为Date类型
猜你喜欢
随机推荐
LocalDateTime转为Date类型
6132. 使数组中所有元素都等于零-快速排序法
excel edit a cell without double clicking
Getting started with IDEA is enough to read this article
Calculate the angle of a line defined by two points
还在纠结报表工具的选型么?来看看这个
解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”
6133. Maximum number of packets
浅析多服务在分布式系统下多事务通信处理机制方案
毕业作业
6133. 分组的最大数量
Always use "noopener" or "noreferrer" for links that open in a new tab
C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
[Camp Experience Post] 2022 Cybersecurity Summer Camp
cmd command
SQL Server(设计数据库--存储过程--触发器)
Quarantine and downgrade
sys_kill系统调用
chrome copies the base64 data of an image
Chapter 11 Working with Dates and Times









