惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
PCI Perspectives
PCI Perspectives
Webroot Blog
Webroot Blog
罗磊的独立博客
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Last Week in AI
Last Week in AI
美团技术团队
Help Net Security
Help Net Security
The Hacker News
The Hacker News
C
Cisco Blogs
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
The Register - Security
The Register - Security
IT之家
IT之家
WordPress大学
WordPress大学
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Help Net Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
NISL@THU
NISL@THU
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
B
Blog
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
S
Security Affairs
小众软件
小众软件
Hacker News: Ask HN
Hacker News: Ask HN
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
A
Arctic Wolf
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence

博客园 - GL_BKY

AI笔记 hippo4j线程池监控落地 Redisson实现分布式限流 Archery SQL 审核查询平台 mybatis-typeHandler解决表字段中json映射对象问题 ConcurrentSkipListMap实现随机数命中权重占比 面试常问题 自动代码质量分析示例搭建 Springboot监听多个端口 Git使用规范 一些问题 netty MQ Spring dubbo+zookeeper JVM 数据结构 redis JS前端加密JAVA后端解密详解
WebLogAspect
GL_BKY · 2023-02-13 · via 博客园 - GL_BKY
package ***;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.MDC;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Aspect
@Slf4j
@Order
public class WebLogAspect {

  @Pointcut("execution(* com.yinker.datacenter.web..*(..))")
  public void webLog(){}

  @Around("webLog()")
  public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
    MDC.clear();
    //记录请求开始执行时间:
    long beginTime = System.currentTimeMillis();
    //获取请求信息
    String methodName = pjp.getSignature().getName();
    //获取请求参数:
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    //获取请求参数类型
    String[] parameterNames = ms.getParameterNames();
    //获取请求参数值
    Object[] parameterValues = pjp.getArgs();
    Map<String,Object> params = Maps.newHashMap();
    for(int i=0;i<parameterNames.length;i++){
      params.put(parameterNames[i],parameterValues[i]);
    }
    Object result;
    try {
      result = pjp.proceed();
    } catch (Throwable throwable) {
      long cost = System.currentTimeMillis() - beginTime;
      log.info("[接口调用记录]:method:{},cost:{}ms,params:{},result:{}",methodName,cost,params,throwable.getMessage());
      throw throwable;
    }
    long cost = System.currentTimeMillis() - beginTime;
    log.info("[接口调用记录]:method:{},cost:{}ms,params:{},result:{}",methodName,cost,params,JSON.toJSONString(result, SerializerFeature.WRITE_MAP_NULL_FEATURES));
    MDC.clear();
    return result;
  }
}