当前位置:网站首页>切面打印调取的方法
切面打印调取的方法
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;
}
}边栏推荐
- 深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
- Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu
- excel remove all carriage return from a cell
- 【参营经历贴】2022网安夏令营
- ELK log collection
- qt-faststart installation and use
- 如何更好的理解的和做好工作?
- Three, mysql storage engine - building database and table operation
- 软技能之UML图
- 颜色透明参数
猜你喜欢
随机推荐
【好书推荐】第一本无人驾驶技术书
excel clear format
excel vertical to horizontal
软技能之UML图
Oracle database is set to read-only and read-write
[C language advanced] file operation (2)
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
cmd指令
数据库表设计规则
【参营经历贴】2022网安夏令营
解决端口占用
深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
vscode hide menu bar
System availability: 3 9s, 4 9s in SRE's mouth... What is it?
对于在新标签页中打开的链接,始终使用“noopener”或“noreferrer”
C语言——分支语句和循环语句
Chapter 12 End-User Task As Shell Scripts
高效工作文档产出归类
【SeaTunnel】从一个数据集成组件演化成企业级的服务
bat 之 特殊字符&转义









