access 로그 삭제 오류 수정

main
semin.baek 4 months ago
parent e828584527
commit 761a4fe9eb

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

Loading…
Cancel
Save