From 5d167b38848c3f69bbcfd952272ac39e48a9af93 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sat, 26 Jun 2021 21:54:26 +0200 Subject: LogHandler now working fine. --- src/main/java/musichub/util/LogHandler.java | 56 +++++++++++++++++++++++++++++ src/main/java/musichub/util/LogWriter.java | 27 -------------- 2 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 src/main/java/musichub/util/LogHandler.java delete mode 100644 src/main/java/musichub/util/LogWriter.java (limited to 'src/main/java/musichub/util') diff --git a/src/main/java/musichub/util/LogHandler.java b/src/main/java/musichub/util/LogHandler.java new file mode 100644 index 0000000..f6522f5 --- /dev/null +++ b/src/main/java/musichub/util/LogHandler.java @@ -0,0 +1,56 @@ +package musichub.util; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.sql.Timestamp; + +/** + * Class offering a log writing method. + * + * @author Aimeric ADJUTOR + * @version 1.0 + */ + +public final class LogHandler { + + /** + * Method that just throws an AssertionError if the class is called + * + * @throws AssertionError you can't instantiate this class + * @author Aimeric ADJUTOR + */ + + public LogHandler() { + throw new AssertionError("You just can't instantiate this class."); + } + + public static void write(String msg, String type) throws IOException { + + Timestamp timestamp = new Timestamp(System.currentTimeMillis()); + + //Create the log using the given message + String logMsg = "\n[" + timestamp + "] " + type + ": " + msg; + + // Define the file name of the file + Path fileName = Path.of("log/spoteezer.log"); + + // Write into the file + Files.writeString(fileName, logMsg, StandardOpenOption.APPEND); + + + } + + public static void read() throws IOException { + Path fileName = Path.of("log/spoteezer.log"); + + // Read the content of the file + String file_content = Files.readString(fileName); + + // Print the content inside the file + System.out.println("\n" + file_content + "\n"); + + } + +} \ No newline at end of file diff --git a/src/main/java/musichub/util/LogWriter.java b/src/main/java/musichub/util/LogWriter.java deleted file mode 100644 index 46d602e..0000000 --- a/src/main/java/musichub/util/LogWriter.java +++ /dev/null @@ -1,27 +0,0 @@ -package musichub.util; - -/** - * Class offering a log writing method. - * - * @author Aimeric ADJUTOR - * @version 1.0 - */ - -public final class LogWriter { - - /** - * Method that just throws an AssertionError if the class is called - * - * @throws AssertionError you can't instantiate this class - * @author Aimeric ADJUTOR - */ - - public LogWriter() { - throw new AssertionError("You just can't instantiate this class."); - } - - public static void write(String msg) { - - } - -} \ No newline at end of file -- cgit v1.2.3