aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/musichub/util
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-06-26 21:54:26 +0200
committerClyhtsuriva <aimeric@adjutor.xyz>2021-06-26 21:54:26 +0200
commit5d167b38848c3f69bbcfd952272ac39e48a9af93 (patch)
tree04ee5b169e21c88a3c5456ac1a73995b65879190 /src/main/java/musichub/util
parent572a9591b7970180a18d1a59e9dab8920c363608 (diff)
LogHandler now working fine.
Diffstat (limited to 'src/main/java/musichub/util')
-rw-r--r--src/main/java/musichub/util/LogHandler.java56
-rw-r--r--src/main/java/musichub/util/LogWriter.java27
2 files changed, 56 insertions, 27 deletions
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