日志超长截断处理

This commit is contained in:
wanxiaoli 2026-06-04 10:14:53 +08:00
parent 36713c0edc
commit d40b56a4ec
3 changed files with 30 additions and 3 deletions

View File

@ -62,11 +62,15 @@ public class SecurityConfig {
auth.requestMatchers("/user/login").anonymous() auth.requestMatchers("/user/login").anonymous()
.requestMatchers("/user/code").permitAll() .requestMatchers("/user/code").permitAll()
.requestMatchers(HttpMethod.GET, .requestMatchers(HttpMethod.GET,
"/",
"/index.html",
"/favicon.ico",
"/*.html", "/*.html",
"/webSocket/**", "/webSocket/**",
"/ws/**", "/ws/**",
"/assets/**", "/assets/**",
"/icon/**").permitAll() "/icon/**",
"/models/**").permitAll()
.requestMatchers( .requestMatchers(
"/swagger-ui.html", "/swagger-ui.html",
"/swagger-ui/**", "/swagger-ui/**",

View File

@ -72,6 +72,7 @@ public class LoginController {
String password = RsaUtils.decryptByPrivateKey(privateKey, String password = RsaUtils.decryptByPrivateKey(privateKey,
user.getPassword()); user.getPassword());
// 是否需要验证码不需要改成false // 是否需要验证码不需要改成false
boolean hascode = true; boolean hascode = true;
if (hascode) { if (hascode) {

View File

@ -150,12 +150,16 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
log.setRequestip(ip); log.setRequestip(ip);
log.setMethod(methodName); log.setMethod(methodName);
log.setUsername(nickname); log.setUsername(nickname);
log.setParams(getParameter(method, joinPoint.getArgs())); log.setParams(truncateWithMark(getParameter(method, joinPoint.getArgs()), 1000, "..."));
log.setBrowser(browser); log.setBrowser(browser);
String operationtype = getOperationtype(signature.getName()); String operationtype = getOperationtype(signature.getName());
log.setOpttype(operationtype); log.setOpttype(operationtype);
log.setLogtime(new Timestamp(System.currentTimeMillis())); log.setLogtime(new Timestamp(System.currentTimeMillis()));
try {
sysLogMapper.insert(log); sysLogMapper.insert(log);
} catch (Exception e) {
// ignore
}
} }
/** /**
@ -216,4 +220,22 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
return type; return type;
} }
private String truncateWithMark(String s, int maxLen, String mark) {
if (StrUtil.isBlank(s)) {
return s;
}
if (maxLen <= 0) {
return "";
}
if (s.length() <= maxLen) {
return s;
}
String safeMark = (mark == null) ? "" : mark;
if (safeMark.length() >= maxLen) {
return safeMark.substring(0, maxLen);
}
int keepLen = maxLen - safeMark.length();
return s.substring(0, keepLen) + safeMark;
}
} }