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

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
S
Security Affairs
S
Secure Thoughts
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Heimdal Security Blog
Forbes - Security
Forbes - Security
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Spread Privacy
Spread Privacy
C
Cybersecurity and Infrastructure Security Agency CISA
Latest news
Latest news
T
Tor Project blog
I
Intezer
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Project Zero
Project Zero
V2EX - 技术
V2EX - 技术
V
Vulnerabilities – Threatpost
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hacker News: Ask HN
Hacker News: Ask HN
S
Schneier on Security
T
Threat Research - Cisco Blogs
Webroot Blog
Webroot Blog
T
Threatpost
Help Net Security
Help Net Security
W
WeLiveSecurity
Know Your Adversary
Know Your Adversary
WordPress大学
WordPress大学
L
LINUX DO - 最新话题
月光博客
月光博客
PCI Perspectives
PCI Perspectives
小众软件
小众软件
爱范儿
爱范儿
博客园 - Franky
Security Latest
Security Latest
Microsoft Azure Blog
Microsoft Azure Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
P
Privacy International News Feed
Y
Y Combinator Blog
P
Palo Alto Networks Blog
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium

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