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.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();
for(File file : files) { if (files != null) {
if(file.lastModified() < cutoff) { for(File file : files) {
file.delete(); if(file.lastModified() < cutoff) {
file.deleteOnExit();
}
} }
} }
} }

Loading…
Cancel
Save