+
+ private static String currentLocalDateTimeStamp() {
+ return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmm"));
+ }
+
+ public static String archiveFileName() {
+ StringBuilder fileName = new StringBuilder();
+ String productName = Platform.getProduct().getName();
+ if (productName != null)
+ fileName.append(productName.replaceAll(" ", "_")).append("-");
+ fileName.append("logs-").append(currentLocalDateTimeStamp());
+ String result = fileName.toString();
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("Resolved log files name {}", result);
+ return result;
+ }
+
+ public static void archiveLogs(String destination) throws IOException {
+ archiveLogs(Paths.get(destination));
+ }
+
+ private static void archiveLogs(Path destination) throws IOException {
+ Path tempDir = Files.createTempDirectory(destination.getFileName().toString());
+ try {
+ Map<String, List<Path>> allLogs = LogCollector.allLogs();
+ for (Entry<String, List<Path>> logEntry : allLogs.entrySet()) {
+ Path subFolder = tempDir.resolve(logEntry.getKey());
+ Files.createDirectory(subFolder);
+ for (Path p : logEntry.getValue()) {
+ try {
+ Files.copy(p, subFolder.resolve(p.getFileName()));
+ } catch (IOException e) {
+ LOGGER.error("Could not copy {}", p.toAbsolutePath(), e);
+ }
+ }
+ }
+ FileUtils.compressZip(tempDir.toAbsolutePath().toString(), destination.toAbsolutePath().toString());
+ } finally {
+ FileUtils.delete(tempDir);
+ }
+ }
+