生成操作日志代码.

This commit is contained in:
lijiahang
2023-10-10 18:37:17 +08:00
parent 730fb000d1
commit 2028d1ee0f
36 changed files with 557 additions and 52 deletions

View File

@@ -93,26 +93,30 @@ public class OperatorLogAspect {
* @param exception exception
*/
private void saveLog(long start, OperatorLog o, Object ret, Throwable exception) {
// 请求信息
Map<String, Object> extra = OperatorLogs.get();
if (!OperatorLogs.isSave(extra)) {
return;
try {
// 请求信息
Map<String, Object> extra = OperatorLogs.get();
if (!OperatorLogs.isSave(extra)) {
return;
}
OperatorLogModel model = new OperatorLogModel();
// 填充使用时间
this.fillUseTime(model, start);
// 填充用户信息
this.fillUserInfo(model);
// 填充请求信息
this.fillRequest(model);
// 填充结果信息
this.fillResult(model, o, ret, exception);
// 填充拓展信息
this.fillExtra(model, extra);
// 填充日志
this.fillLogInfo(model, extra, o);
// 插入日志
this.asyncSaveLog(model);
} catch (Exception e) {
log.error("操作日志保存失败", e);
}
OperatorLogModel model = new OperatorLogModel();
// 填充使用时间
this.fillUseTime(model, start);
// 填充用户信息
this.fillUserInfo(model);
// 填充请求信息
this.fillRequest(model);
// 填充结果信息
this.fillResult(model, o, ret, exception);
// 填充拓展信息
this.fillExtra(model, extra);
// 填充日志
this.fillLogInfo(model, extra, o);
// 插入日志
this.asyncSaveLog(model);
}
/**
@@ -151,7 +155,7 @@ public class OperatorLogAspect {
String address = Servlets.getRemoteAddr(request);
model.setAddress(address);
model.setLocation(IpUtils.getLocation(address));
model.setUserAgent(Servlets.getUserAgent(request));
model.setUserAgent(Strings.retain(Servlets.getUserAgent(request), operatorLogConfig.getUserAgentLength()));
});
}
@@ -189,7 +193,9 @@ public class OperatorLogAspect {
*/
private void fillExtra(OperatorLogModel model, Map<String, Object> extra) {
// 脱敏
model.setExtra(JSON.toJSONString(extra, desensitizeValueFilter));
if (extra != null) {
model.setExtra(JSON.toJSONString(extra, desensitizeValueFilter));
}
}
/**

View File

@@ -19,7 +19,13 @@ public class OperatorLogConfig {
*/
private Integer errorMessageLength;
/**
* userAgent 长度
*/
private Integer userAgentLength;
public OperatorLogConfig() {
this.errorMessageLength = 255;
this.userAgentLength = 128;
}
}

View File

@@ -32,11 +32,10 @@ public class OperatorTypeHolder {
/**
* 设置类型
*
* @param key key
* @param type type
*/
public static void set(String key, OperatorType type) {
TYPES.put(key, type);
public static void set(OperatorType type) {
TYPES.put(type.getType(), type);
}
}

View File

@@ -10,8 +10,14 @@
{
"name": "orion.operator-log.error-message-length",
"type": "java.lang.Integer",
"description": "日志打印模型.",
"description": "错误信息长度.",
"defaultValue": "255"
},
{
"name": "orion.operator-log.user-agent-length",
"type": "java.lang.Integer",
"description": "userAgent 长度.",
"defaultValue": "128"
}
]
}

View File

@@ -20,28 +20,28 @@ import java.util.Date;
@Data
public class BaseDO implements Serializable {
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "修改时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
@Schema(description = "创建人")
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
private String creator;
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR)
@Schema(description = "修改人")
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR)
private String updater;
/**
* @see com.orion.ops.framework.common.constant.Const#NOT_DELETE
* @see com.orion.ops.framework.common.constant.Const#IS_DELETED
*/
@TableLogic
@Schema(description = "是否删除 0未删除 1已删除")
@TableLogic
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.TINYINT)
private Boolean deleted;