去掉plumelog
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package org.nl.config.plumelog;
|
||||
|
||||
import com.plumelog.trace.aspect.AbstractAspect;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 全局打点 需要自己定义切入点 (demo 如下 ) 当定义全局打点时,手动打点就会失效
|
||||
* @Date: 2023/1/29
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class AspectConfig extends AbstractAspect {
|
||||
|
||||
//@Pointcut注解声明切点
|
||||
@Pointcut("within(org.nl..*) && !within(org.nl.modules.mnt.websocket.WebSocketServer)")
|
||||
public void performance() {
|
||||
}
|
||||
@Around("performance()")
|
||||
public Object around(JoinPoint joinPoint) throws Throwable {
|
||||
return aroundExecute(joinPoint);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.nl.config.plumelog;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
* @Date: 2023/1/29
|
||||
*/
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 自定义拦截器,添加拦截路径和排除拦截路径
|
||||
registry.addInterceptor(new PlumelogInterceptor()).addPathPatterns("/**");
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package org.nl.config.plumelog;
|
||||
|
||||
import com.plumelog.core.TraceId;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
* @Date: 2023/1/29
|
||||
*/
|
||||
@Configuration
|
||||
public class PlumelogInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
//设置TraceID值,不埋此点链路ID就没有
|
||||
TraceId.logTraceID.set(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ package org.nl.modules.logging.aspect;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
@@ -42,7 +42,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@@ -76,7 +79,6 @@ public class LogAspect {
|
||||
*/
|
||||
@Around("logPointcut()")
|
||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
String trackId = UUID.randomUUID().toString();
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
// 方法路径
|
||||
@@ -87,51 +89,54 @@ public class LogAspect {
|
||||
|
||||
//是否输出到日志文件
|
||||
if (logInfo.isPrintToLogFile()) {
|
||||
log.info("track_id:{},请求方法:{},请求方法参数:{}",trackId,methodName,params);
|
||||
log.info("请求方法:{}", methodName);
|
||||
log.info("请求方法参数:{}", params);
|
||||
}
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
String requestIp = StringUtils.getIp(request);
|
||||
|
||||
|
||||
Object result;
|
||||
currentTime.set(System.currentTimeMillis());
|
||||
try {
|
||||
result = joinPoint.proceed();
|
||||
//是否把日志存到日志表
|
||||
if (logInfo.isAddLogTable()) {
|
||||
Log log = new Log("INFO", System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log);
|
||||
}
|
||||
if (logInfo.isInterfaceLog()) {
|
||||
try {
|
||||
WQLObject interfaceLog = WQLObject.getWQLObject("sys_interface_log");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("log_id", IdUtil.getStringId());
|
||||
json.put("description", logInfo.value());
|
||||
json.put("log_type", logInfo.interfaceLogType().getDesc());
|
||||
json.put("log_level", "1");
|
||||
json.put("method", methodName);
|
||||
json.put("params", getParameter(method, joinPoint.getArgs()));
|
||||
json.put("request_ip", StringUtils.getIp(request));
|
||||
json.put("time", System.currentTimeMillis() - currentTime.get());
|
||||
json.put("username", getUsername());
|
||||
json.put("address", StringUtils.getCityInfo(requestIp));
|
||||
json.put("browser", StringUtils.getBrowser(request));
|
||||
json.put("exception_detail", IdUtil.getStringId());
|
||||
json.put("create_time", DateUtil.now());
|
||||
json.put("return_result", JSONObject.fromObject(result).getJSONObject("body"));
|
||||
interfaceLog.insert(json);
|
||||
} catch (Exception e) {
|
||||
result = joinPoint.proceed();
|
||||
|
||||
}
|
||||
}
|
||||
}catch (Exception ex){
|
||||
log.error("track_id:{},error:{}",trackId,ex.getMessage());
|
||||
Log log = new Log("ERROR", System.currentTimeMillis() - currentTime.get());
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
|
||||
String requestIp = StringUtils.getIp(request);
|
||||
//是否把日志存到日志表
|
||||
if (logInfo.isAddLogTable()) {
|
||||
Log log = new Log("INFO", System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes());
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
|
||||
throw ex;
|
||||
|
||||
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log);
|
||||
}
|
||||
|
||||
|
||||
//保存到接口日志表
|
||||
if (logInfo.isInterfaceLog()) {
|
||||
try {
|
||||
System.out.println("日志存储到接口日志表!");
|
||||
WQLObject interfaceLog = WQLObject.getWQLObject("sys_interface_log");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("log_id", IdUtil.getStringId());
|
||||
json.put("description", logInfo.value());
|
||||
json.put("log_type", logInfo.interfaceLogType().getDesc());
|
||||
json.put("log_level", "1");
|
||||
json.put("method", methodName);
|
||||
json.put("params", getParameter(method, joinPoint.getArgs()));
|
||||
json.put("request_ip", StringUtils.getIp(request));
|
||||
json.put("time", System.currentTimeMillis() - currentTime.get());
|
||||
json.put("username", getUsername());
|
||||
json.put("address", StringUtils.getCityInfo(requestIp));
|
||||
json.put("browser", StringUtils.getBrowser(request));
|
||||
json.put("exception_detail", IdUtil.getStringId());
|
||||
json.put("create_time", DateUtil.now());
|
||||
json.put("return_result", JSONObject.parse(result.toString()));
|
||||
interfaceLog.insert(json);
|
||||
} catch (Exception e) {
|
||||
System.out.println("接口日志保存异常!"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -171,7 +176,7 @@ public class LogAspect {
|
||||
* @param joinPoint join point for advice
|
||||
* @param e exception
|
||||
*/
|
||||
// @AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
||||
@AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||
Log log = new Log("ERROR", System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
|
||||
Reference in New Issue
Block a user