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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
博客园_首页
WordPress大学
WordPress大学
博客园 - 聂微东
P
Privacy International News Feed
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
月光博客
月光博客
NISL@THU
NISL@THU
美团技术团队
T
Tailwind CSS Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Hacker News
The Hacker News
B
Blog
P
Palo Alto Networks Blog
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
The Register - Security
The Register - Security
S
Securelist
A
Arctic Wolf
MyScale Blog
MyScale Blog
H
Help Net Security
N
Netflix TechBlog - Medium
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Threatpost
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Latest
Security Latest
T
Tor Project blog
V
Vulnerabilities – Threatpost
V
V2EX
AI
AI
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
Simon Willison's Weblog
Simon Willison's Weblog
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Heimdal Security Blog
Google Online Security Blog
Google Online Security Blog
Know Your Adversary
Know Your Adversary

博客园 - 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;
  }
}