aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/musichub/main/Main.java12
-rw-r--r--src/main/java/musichub/util/LogHandler.java56
-rw-r--r--src/main/java/musichub/util/LogWriter.java27
3 files changed, 67 insertions, 28 deletions
diff --git a/src/main/java/musichub/main/Main.java b/src/main/java/musichub/main/Main.java
index e06d056..e7ca721 100644
--- a/src/main/java/musichub/main/Main.java
+++ b/src/main/java/musichub/main/Main.java
@@ -1,6 +1,7 @@
package musichub.main;
import musichub.business.*;
+import musichub.util.LogHandler;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
@@ -93,7 +94,9 @@ public class Main {
System.out.println("Song content: ");
String content = scan.nextLine();
if (!isPathValid(content)) {
- System.out.println("The music file was not found with the path you've provided.\nType h for available commands");
+ String logMsg = "The music file was not found with the path you've provided.";
+ LogHandler.write(logMsg, "WARNING"); //write a line in the log file
+ System.out.println(logMsg + "\nType h for available commands");
choice = scan.nextLine();
break;
}
@@ -240,6 +243,12 @@ public class Main {
printAvailableCommands();
choice = scan.nextLine();
break;
+ case 'o':
+ //consult the app logs
+ LogHandler.read();
+ System.out.println("Type h for available commands");
+ choice = scan.nextLine();
+ break;
default:
break;
@@ -260,6 +269,7 @@ public class Main {
System.out.println("p: create a new playlist from existing songs and audio books");
System.out.println("-: delete an existing playlist");
System.out.println("s: save elements, albums, playlists");
+ System.out.println("o: consult the app logs");
System.out.println("q: quit program");
}
} \ No newline at end of file
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