基础信息提交
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
package com.njcn.common.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年07月08日 20:03
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LogInfoDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 登录名
|
||||
*/
|
||||
private String loginName;
|
||||
|
||||
/**
|
||||
* 用户已登录:用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
|
||||
private String ip;
|
||||
|
||||
private String operate;
|
||||
|
||||
private String operateType;
|
||||
|
||||
/**
|
||||
* 操作结果 0.失败 1.成功
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 失败原因
|
||||
*/
|
||||
private String failReason;
|
||||
|
||||
/**
|
||||
* 严重度 0.普通 1.中等 2.严重
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 事件类型 0.业务事件 1.系统事件
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 0 未登录; 1 已登录
|
||||
*/
|
||||
private String userIndex;
|
||||
|
||||
/**
|
||||
* 0 未登录; 1 已登录
|
||||
*/
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.njcn.common.pojo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月25日 09:40
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SelectOption implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.njcn.common.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年03月11日 11:29
|
||||
*/
|
||||
@Data
|
||||
public class UserTokenInfo implements Serializable {
|
||||
|
||||
/**
|
||||
* 通行token
|
||||
*/
|
||||
private String accessTokenJti;
|
||||
|
||||
/**
|
||||
* 刷新token
|
||||
*/
|
||||
private String refreshToken;
|
||||
|
||||
|
||||
/**
|
||||
* refreshToken的生命周期结点
|
||||
*/
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime refreshTokenExpire;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.njcn.common.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年04月21日 09:16
|
||||
*/
|
||||
public class ExceptionUtil {
|
||||
|
||||
private static final String PACKAGE_PREFIX = "com.njcn";
|
||||
|
||||
private static final String CONTROLLER = "controller";
|
||||
|
||||
/**
|
||||
* 遍历出当前异常在本服务中栈堆信息----异常发生最初位置
|
||||
* 本服务所有的包名均需要以com.njcn为前缀
|
||||
* 该前缀不需要做配置管理,通常项目创建之初约定完便可。
|
||||
*/
|
||||
public static String getExceptionServerStackInfo(Exception exception) {
|
||||
StackTraceElement[] stackTrace = exception.getStackTrace();
|
||||
List<StackTraceElement> originalStackTraceElements = Arrays.asList(stackTrace);
|
||||
//遍历出本服务的栈堆信息
|
||||
List<StackTraceElement> stackTraceElements = originalStackTraceElements.stream().filter(stackInfo -> stackInfo.getClassName().contains(PACKAGE_PREFIX)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(stackTraceElements)) {
|
||||
return stackTraceElements.get(0).toString();
|
||||
} else if (CollectionUtil.isNotEmpty(originalStackTraceElements)) {
|
||||
return originalStackTraceElements.get(0).toString();
|
||||
}
|
||||
return "未找到当前异常的堆栈信息";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 遍历出当前异常在本服务中栈堆信息----堆栈的所有信息
|
||||
* 本服务所有的包名均需要以com.njcn为前缀
|
||||
* 该前缀不需要做配置管理,通常项目创建之初约定完便可。
|
||||
*/
|
||||
public static List<String> getAllExceptionServerStackInfo(Exception exception) {
|
||||
StackTraceElement[] stackTrace = exception.getStackTrace();
|
||||
List<StackTraceElement> originalStackTraceElements = Arrays.asList(stackTrace);
|
||||
//遍历出本服务的栈堆信息
|
||||
List<StackTraceElement> stackTraceElements = originalStackTraceElements.stream().filter(stackInfo -> stackInfo.getClassName().contains(PACKAGE_PREFIX)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(stackTraceElements)) {
|
||||
return stackTraceElements.stream().map(StackTraceElement::toString).collect(Collectors.toList());
|
||||
} else if (CollectionUtil.isNotEmpty(originalStackTraceElements)) {
|
||||
return originalStackTraceElements.stream().map(StackTraceElement::toString).collect(Collectors.toList());
|
||||
}
|
||||
List<String> noStackInfos = new ArrayList<>();
|
||||
noStackInfos.add("未找到当前异常的堆栈信息");
|
||||
return noStackInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历出当前异常堆栈的所有信息
|
||||
* 本服务所有的包名均需要以com.njcn为前缀
|
||||
* 该前缀不需要做配置管理,通常项目创建之初约定完便可。
|
||||
*/
|
||||
public static List<String> getAllExceptionStackInfo(Exception exception) {
|
||||
StackTraceElement[] stackTrace = exception.getStackTrace();
|
||||
List<StackTraceElement> originalStackTraceElements = Arrays.asList(stackTrace);
|
||||
if (CollectionUtil.isNotEmpty(originalStackTraceElements)) {
|
||||
return originalStackTraceElements.stream().map(StackTraceElement::toString).collect(Collectors.toList());
|
||||
}
|
||||
List<String> noStackInfos = new ArrayList<>();
|
||||
noStackInfos.add("未找到当前异常的堆栈信息");
|
||||
return noStackInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历异常信息栈,获取信息栈中第一个出现的controller以及方法名称
|
||||
* 用于反射获取注解内容,比如方法名,操作类型,操作严重度
|
||||
* <p>
|
||||
* 实际情况可能会出现没有controller入口的情况导致的异常,比如网关gateway内所有请求
|
||||
*/
|
||||
public static List<String> getFirstControllerAndMethodName(Exception exception) {
|
||||
List<String> controllerInfo = new ArrayList<>();
|
||||
StackTraceElement[] stackTraces = exception.getStackTrace();
|
||||
List<StackTraceElement> stackTraceElements = Stream.of(stackTraces)
|
||||
.filter(stackInfo -> stackInfo.getClassName().contains(PACKAGE_PREFIX) && stackInfo.getClassName().contains(CONTROLLER))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(stackTraceElements)) {
|
||||
StackTraceElement stackTraceElement = stackTraceElements.get(0);
|
||||
String stackInfo = stackTraceElement.toString();
|
||||
|
||||
String packageInfo = stackInfo.substring(stackInfo.indexOf(PACKAGE_PREFIX));
|
||||
packageInfo = packageInfo.substring(0, packageInfo.indexOf("("));
|
||||
String controllerName = packageInfo.substring(0, packageInfo.lastIndexOf(CharUtil.DOT));
|
||||
String methodName = packageInfo.substring(packageInfo.lastIndexOf(CharUtil.DOT) + 1);
|
||||
if(methodName.indexOf('$')>0){
|
||||
methodName = methodName.substring(0, methodName.indexOf('$'));
|
||||
}
|
||||
Collections.addAll(controllerInfo, controllerName, methodName);
|
||||
}
|
||||
return controllerInfo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
54
njcn-common/src/main/java/com/njcn/common/utils/LogUtil.java
Normal file
54
njcn-common/src/main/java/com/njcn/common/utils/LogUtil.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.njcn.common.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2024/10/30 14:50
|
||||
*/
|
||||
@Slf4j
|
||||
public class LogUtil {
|
||||
|
||||
/**
|
||||
* 将判断是否开启debug模式,抽取单独的方法,必要时查看敏感信息
|
||||
*
|
||||
* @param log 日志输出器
|
||||
*/
|
||||
public static void njcnDebug(Logger log, String format, Object... args) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.info(format, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将判断是否开启debug模式,抽取单独的方法,必要时查看debug级别信息
|
||||
* 批量输出堆栈日志信息
|
||||
*
|
||||
* @param log 日志输出器
|
||||
*/
|
||||
public static void njcnPatchDebug(Logger log, List<String> stackInfos) {
|
||||
if (log.isDebugEnabled()) {
|
||||
stackInfos.forEach(log::error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 区分是否开启debug模式,输出系统异常日志信息
|
||||
* 若开启debug模式,则输出所有的堆栈信息
|
||||
* 否则只输出第一行日志信息
|
||||
*
|
||||
* @param exception 异常
|
||||
*/
|
||||
public static void logExceptionStackInfo(String exceptionName, Exception exception) {
|
||||
//若开启了debug模式,则输出所有的栈堆信息
|
||||
njcnPatchDebug(log, ExceptionUtil.getAllExceptionStackInfo(exception));
|
||||
log.error("{}{},目标文件:{}",exceptionName, exception, ExceptionUtil.getExceptionServerStackInfo(exception));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user