|
|
|
@ -32,7 +32,7 @@ public class AccessLogConfiguration implements WebServerFactoryCustomizer<Tomcat
|
|
|
|
accessLogValve.setSuffix(".log");
|
|
|
|
accessLogValve.setSuffix(".log");
|
|
|
|
accessLogValve.setRotatable(true);
|
|
|
|
accessLogValve.setRotatable(true);
|
|
|
|
accessLogValve.setRenameOnRotate(true);
|
|
|
|
accessLogValve.setRenameOnRotate(true);
|
|
|
|
accessLogValve.setFileDateFormat("yyyy-MM-dd");
|
|
|
|
accessLogValve.setFileDateFormat(".yyyy-MM-dd");
|
|
|
|
accessLogValve.setRequestAttributesEnabled(true);
|
|
|
|
accessLogValve.setRequestAttributesEnabled(true);
|
|
|
|
factory.addContextValves(accessLogValve);
|
|
|
|
factory.addContextValves(accessLogValve);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -43,13 +43,15 @@ public class AccessLogConfiguration implements WebServerFactoryCustomizer<Tomcat
|
|
|
|
@Scheduled(cron = "0 0 3 * * *")
|
|
|
|
@Scheduled(cron = "0 0 3 * * *")
|
|
|
|
public void cleanAccessLog() {
|
|
|
|
public void cleanAccessLog() {
|
|
|
|
AgentConfigDto agentConfigDto = this.agentConfigReader.getAgentConfigDto();
|
|
|
|
AgentConfigDto agentConfigDto = this.agentConfigReader.getAgentConfigDto();
|
|
|
|
File logFileDirFile = new File(Paths.get(agentConfigDto.getLogging().getLogDirectory()).toString());
|
|
|
|
File logFileDirFile = new File(Paths.get(agentConfigDto.getLogging().getLogDirectory()).toString(), "access");
|
|
|
|
File[] files = logFileDirFile.listFiles((dir, name) -> name.startsWith("access."));
|
|
|
|
File[] files = logFileDirFile.listFiles((dir, name) -> name.startsWith("access_log"));
|
|
|
|
long maxHistory = agentConfigDto.getLogging().getMaxHistory();
|
|
|
|
long maxHistory = agentConfigDto.getLogging().getMaxHistory();
|
|
|
|
long cutoff = System.currentTimeMillis() - Duration.ofDays(maxHistory).toMillis();
|
|
|
|
long cutoff = System.currentTimeMillis() - Duration.ofDays(maxHistory).toMillis();
|
|
|
|
|
|
|
|
if (files != null) {
|
|
|
|
for(File file : files) {
|
|
|
|
for(File file : files) {
|
|
|
|
if(file.lastModified() < cutoff) {
|
|
|
|
if(file.lastModified() < cutoff) {
|
|
|
|
file.delete();
|
|
|
|
file.deleteOnExit();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|