From d95d5048b4d79272c274d9bb2a7f3b42432bc53f Mon Sep 17 00:00:00 2001 From: louisld Date: Thu, 31 Dec 2020 13:02:05 +0100 Subject: [PATCH] Added log system --- .../fatestaynight/packager/GoogleAPI.java | 2 +- .../packager/PrintStreamCapturer.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/bloomenetwork/fatestaynight/packager/GoogleAPI.java b/src/main/java/fr/bloomenetwork/fatestaynight/packager/GoogleAPI.java index a81c1e5..82dd186 100644 --- a/src/main/java/fr/bloomenetwork/fatestaynight/packager/GoogleAPI.java +++ b/src/main/java/fr/bloomenetwork/fatestaynight/packager/GoogleAPI.java @@ -93,7 +93,7 @@ public String getFolderIdByName(String name) throws Exception { .setPageToken(pageToken) .execute(); for (File file : result.getFiles()) { - System.out.println("Répertoire " + name + " trouvé.\n"); + Utils.print("Répertoire " + name + " trouvé.\n"); return file.getId(); } pageToken = result.getNextPageToken(); diff --git a/src/main/java/fr/bloomenetwork/fatestaynight/packager/PrintStreamCapturer.java b/src/main/java/fr/bloomenetwork/fatestaynight/packager/PrintStreamCapturer.java index 2a6efae..184343e 100644 --- a/src/main/java/fr/bloomenetwork/fatestaynight/packager/PrintStreamCapturer.java +++ b/src/main/java/fr/bloomenetwork/fatestaynight/packager/PrintStreamCapturer.java @@ -1,6 +1,15 @@ package fr.bloomenetwork.fatestaynight.packager; +import java.io.File; +import java.io.IOException; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import javax.swing.JTextArea; @@ -12,12 +21,21 @@ public class PrintStreamCapturer extends PrintStream { private JTextArea text; private boolean atLineStart; private String indent; + private static final String LOG_PATH = "./logs/"; + private Path logFile; public PrintStreamCapturer(JTextArea textArea, PrintStream capturedStream, String indent) { super(capturedStream); this.text = textArea; this.indent = indent; this.atLineStart = true; + new File(LOG_PATH).mkdirs(); + this.logFile = Paths.get(LOG_PATH + "FSN Packager - " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH-mm-ss")) + ".log"); + try { + Files.createFile(logFile); + } catch (IOException e) { + e.printStackTrace(); + } } public PrintStreamCapturer(JTextArea textArea, PrintStream capturedStream) { @@ -31,6 +49,11 @@ private void writeToTextArea(String str) { text.append(str); } } + try { + Files.write(logFile, str.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND); + } catch (IOException e) { + e.printStackTrace(); + } } private void write(String str) {