Skip to content

Commit

Permalink
Added log system
Browse files Browse the repository at this point in the history
  • Loading branch information
louisld committed Dec 31, 2020
1 parent b9ba295 commit d95d504
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit d95d504

Please sign in to comment.