@Test public void cleanup() throws Exception { when(taskLogCleanup.getTaskLogHome()).thenReturn(tempTaskFolder.getAbsolutePath()); taskLogCleanup.cleanup(); assertTrue(todayFile.exists()); assertTrue(yesterdayFile.exists()); assertFalse(twoDaysOldFile.exists()); }
void cleanup() { String taskLogsHome = getTaskLogHome(); if (taskLogsHome == null) { log.warn("Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml"); return; } File logFilesHome = new File(taskLogsHome); log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays); LocalDate now = LocalDate.now().minusDays(numberOfDays); Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate); Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter); filesToDelete.forEachRemaining(f -> { try { forceDelete(f); log.info("Removed task log file {}", f.toString()); } catch (IOException e) { log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage()); } } ); }
TaskLogCleanup extends ComponentSupport { void cleanup() { String taskLogsHome = getTaskLogHome(); if (taskLogsHome == null) { log.warn("Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml"); return; } File logFilesHome = new File(taskLogsHome); log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays); LocalDate now = LocalDate.now().minusDays(numberOfDays); Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate); Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter); filesToDelete.forEachRemaining(f -> { try { forceDelete(f); log.info("Removed task log file {}", f.toString()); } catch (IOException e) { log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage()); } } ); } }
TaskLogCleanup extends ComponentSupport { void cleanup() { String taskLogsHome = getTaskLogHome(); if (taskLogsHome == null) { log.warn("Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml"); return; } File logFilesHome = new File(taskLogsHome); log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays); LocalDate now = LocalDate.now().minusDays(numberOfDays); Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate); Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter); filesToDelete.forEachRemaining(f -> { try { forceDelete(f); log.info("Removed task log file {}", f.toString()); } catch (IOException e) { log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage()); } } ); } @Inject  TaskLogCleanup(@Named("${nexus.tasks.log.cleanup.numberOfDays:-30}") final Integer numberOfDays); }
TaskLogCleanup extends ComponentSupport { void cleanup() { String taskLogsHome = getTaskLogHome(); if (taskLogsHome == null) { log.warn("Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml"); return; } File logFilesHome = new File(taskLogsHome); log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays); LocalDate now = LocalDate.now().minusDays(numberOfDays); Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate); Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter); filesToDelete.forEachRemaining(f -> { try { forceDelete(f); log.info("Removed task log file {}", f.toString()); } catch (IOException e) { log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage()); } } ); } @Inject  TaskLogCleanup(@Named("${nexus.tasks.log.cleanup.numberOfDays:-30}") final Integer numberOfDays);  }
TaskLogCleanup extends ComponentSupport { void cleanup() { String taskLogsHome = getTaskLogHome(); if (taskLogsHome == null) { log.warn("Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml"); return; } File logFilesHome = new File(taskLogsHome); log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays); LocalDate now = LocalDate.now().minusDays(numberOfDays); Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate); Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter); filesToDelete.forEachRemaining(f -> { try { forceDelete(f); log.info("Removed task log file {}", f.toString()); } catch (IOException e) { log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage()); } } ); } @Inject  TaskLogCleanup(@Named("${nexus.tasks.log.cleanup.numberOfDays:-30}") final Integer numberOfDays);   }