log
This commit is contained in:
@@ -42,10 +42,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
@@ -79,6 +76,7 @@ public class LogAspect {
|
|||||||
*/
|
*/
|
||||||
@Around("logPointcut()")
|
@Around("logPointcut()")
|
||||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
String trackId = UUID.randomUUID().toString();
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
// 方法路径
|
// 方法路径
|
||||||
@@ -89,54 +87,51 @@ public class LogAspect {
|
|||||||
|
|
||||||
//是否输出到日志文件
|
//是否输出到日志文件
|
||||||
if (logInfo.isPrintToLogFile()) {
|
if (logInfo.isPrintToLogFile()) {
|
||||||
log.info("请求方法:{}", methodName);
|
log.info("track_id:{},请求方法:{},请求方法参数:{}",trackId,methodName,params);
|
||||||
log.info("请求方法参数:{}", params);
|
|
||||||
}
|
}
|
||||||
|
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||||
|
String requestIp = StringUtils.getIp(request);
|
||||||
Object result;
|
Object result;
|
||||||
currentTime.set(System.currentTimeMillis());
|
currentTime.set(System.currentTimeMillis());
|
||||||
result = joinPoint.proceed();
|
try {
|
||||||
|
result = joinPoint.proceed();
|
||||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
//是否把日志存到日志表
|
||||||
|
if (logInfo.isAddLogTable()) {
|
||||||
String requestIp = StringUtils.getIp(request);
|
Log log = new Log("INFO", System.currentTimeMillis() - currentTime.get());
|
||||||
//是否把日志存到日志表
|
currentTime.remove();
|
||||||
if (logInfo.isAddLogTable()) {
|
logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log);
|
||||||
Log log = new Log("INFO", System.currentTimeMillis() - currentTime.get());
|
|
||||||
currentTime.remove();
|
|
||||||
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
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.parse(result.toString()));
|
||||||
|
interfaceLog.insert(json);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception ex){
|
||||||
|
log.error("track_id:{},error:{}",trackId,ex.getMessage());
|
||||||
|
Log log = new Log("ERROR", 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;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +171,7 @@ public class LogAspect {
|
|||||||
* @param joinPoint join point for advice
|
* @param joinPoint join point for advice
|
||||||
* @param e exception
|
* @param e exception
|
||||||
*/
|
*/
|
||||||
@AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
// @AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
||||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||||
Log log = new Log("ERROR", System.currentTimeMillis() - currentTime.get());
|
Log log = new Log("ERROR", System.currentTimeMillis() - currentTime.get());
|
||||||
currentTime.remove();
|
currentTime.remove();
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class AcsToWmsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/shipDeviceUpdate")
|
@PostMapping("/shipDeviceUpdate")
|
||||||
@Log(value = "输送线光电无货上报", isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
|
// @Log(value = "输送线光电无货上报", isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
|
||||||
@ApiOperation("输送线光电无货上报")
|
@ApiOperation("输送线光电无货上报")
|
||||||
@SaIgnore
|
@SaIgnore
|
||||||
public ResponseEntity<Object> shipDeviceUpdate(@RequestBody JSONObject jo) {
|
public ResponseEntity<Object> shipDeviceUpdate(@RequestBody JSONObject jo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user