日志超长截断处理
This commit is contained in:
parent
36713c0edc
commit
d40b56a4ec
@ -62,11 +62,15 @@ public class SecurityConfig {
|
||||
auth.requestMatchers("/user/login").anonymous()
|
||||
.requestMatchers("/user/code").permitAll()
|
||||
.requestMatchers(HttpMethod.GET,
|
||||
"/",
|
||||
"/index.html",
|
||||
"/favicon.ico",
|
||||
"/*.html",
|
||||
"/webSocket/**",
|
||||
"/ws/**",
|
||||
"/assets/**",
|
||||
"/icon/**").permitAll()
|
||||
"/icon/**",
|
||||
"/models/**").permitAll()
|
||||
.requestMatchers(
|
||||
"/swagger-ui.html",
|
||||
"/swagger-ui/**",
|
||||
|
||||
@ -72,6 +72,7 @@ public class LoginController {
|
||||
String password = RsaUtils.decryptByPrivateKey(privateKey,
|
||||
user.getPassword());
|
||||
|
||||
|
||||
// 是否需要验证码不需要改成false
|
||||
boolean hascode = true;
|
||||
if (hascode) {
|
||||
|
||||
@ -150,12 +150,16 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||
log.setRequestip(ip);
|
||||
log.setMethod(methodName);
|
||||
log.setUsername(nickname);
|
||||
log.setParams(getParameter(method, joinPoint.getArgs()));
|
||||
log.setParams(truncateWithMark(getParameter(method, joinPoint.getArgs()), 1000, "..."));
|
||||
log.setBrowser(browser);
|
||||
String operationtype = getOperationtype(signature.getName());
|
||||
log.setOpttype(operationtype);
|
||||
log.setLogtime(new Timestamp(System.currentTimeMillis()));
|
||||
sysLogMapper.insert(log);
|
||||
try {
|
||||
sysLogMapper.insert(log);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,4 +220,22 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user