From 0572c31567b386f0845fdaa7d595ceeef01b24b7 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 28 Jun 2021 20:34:08 +0200 Subject: Added logs a little bit everywhere and fixed the r feature. --- log/spoteezer.log | 42 ++++++++++++++++++++++- src/main/java/musichub/business/AudioElement.java | 18 +++++++--- src/main/java/musichub/main/Main.java | 14 +++++++- src/main/java/musichub/util/Policy.java | 6 ++++ 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/log/spoteezer.log b/log/spoteezer.log index fc6ea56..7904af2 100644 --- a/log/spoteezer.log +++ b/log/spoteezer.log @@ -1,4 +1,44 @@ [yyyy-MM-dd HH:mm:ss.SSS] TYPE: Message [2021-06-27 13:23:40.286] TEST: JUnit test [2021-06-28 18:33:51.708] ERROR: You've not provided a number for the length. -[2021-06-28 18:37:56.051] ERROR: The music file cannot be found with the path you've provided or the extension is not .wav \ No newline at end of file +[2021-06-28 18:37:56.051] ERROR: The music file cannot be found with the path you've provided or the extension is not .wav +[2021-06-28 20:04:37.592] INFO: Terms accepted by the user. +[2021-06-28 20:07:42.232] INFO: Terms accepted by the user. +[2021-06-28 20:07:45.175] WARNING: No album found with the requested title +[2021-06-28 20:15:32.074] INFO: Terms accepted by the user. +[2021-06-28 20:15:37.695] ERROR: The music file cannot be found with the path you've provided or the extension is not .wav +[2021-06-28 20:15:41.873] INFO: Playlist successfully deleted +[2021-06-28 20:15:52.733] INFO: Playlist successfully deleted +[2021-06-28 20:16:00.783] INFO: Playlist successfully created +[2021-06-28 20:16:13.904] INFO: Terms accepted by the user. +[2021-06-28 20:16:46.773] INFO: Song successfully added to the album +[2021-06-28 20:22:21.365] INFO: Terms accepted by the user. +[2021-06-28 20:22:29.053] INFO: Music started +[2021-06-28 20:22:32.131] INFO: Music started +[2021-06-28 20:22:33.812] INFO: Music started +[2021-06-28 20:22:36.089] INFO: Music reset +[2021-06-28 20:22:37.044] INFO: Music stopped +[2021-06-28 20:23:35.383] INFO: Music stopped +[2021-06-28 20:25:57.365] INFO: Music stopped +[2021-06-28 20:26:27.681] INFO: Music stopped +[2021-06-28 20:26:39.722] INFO: Music started +[2021-06-28 20:26:43.114] INFO: Music stopped +[2021-06-28 20:26:44.358] INFO: Music stopped +[2021-06-28 20:27:19.435] INFO: Terms accepted by the user. +[2021-06-28 20:27:27.853] INFO: Music started +[2021-06-28 20:27:29.052] INFO: Music stopped +[2021-06-28 20:27:29.756] INFO: Music stopped +[2021-06-28 20:28:43.556] INFO: Terms accepted by the user. +[2021-06-28 20:28:49.793] INFO: Music started +[2021-06-28 20:28:51.105] INFO: Music stopped +[2021-06-28 20:31:00.065] INFO: Terms accepted by the user. +[2021-06-28 20:31:04.007] INFO: Elements, albums and playlists successfully saved +[2021-06-28 20:31:14.871] INFO: Terms accepted by the user. +[2021-06-28 20:31:18.798] INFO: Music started +[2021-06-28 20:31:20.634] INFO: Music stopped +[2021-06-28 20:32:24.641] INFO: Terms accepted by the user. +[2021-06-28 20:32:29.821] INFO: Music started +[2021-06-28 20:32:31.447] INFO: Music stopped +[2021-06-28 20:32:32.647] INFO: Music stopped +[2021-06-28 20:32:43.836] INFO: Music started +[2021-06-28 20:32:52.768] INFO: Music stopped \ No newline at end of file diff --git a/src/main/java/musichub/business/AudioElement.java b/src/main/java/musichub/business/AudioElement.java index fa410d8..80a649a 100644 --- a/src/main/java/musichub/business/AudioElement.java +++ b/src/main/java/musichub/business/AudioElement.java @@ -1,5 +1,6 @@ package musichub.business; +import musichub.util.LogHandler; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -107,12 +108,21 @@ public abstract class AudioElement { action = action.toUpperCase(); switch (action) { - case "S", "Q" -> clip.stop(); - case "P" -> clip.start(); - case "R" -> clip.setMicrosecondPosition(0); + case "S", "Q" -> { + clip.stop(); + LogHandler.write("Music stopped", "INFO"); + } + case "P" -> { + clip.start(); + LogHandler.write("Music started", "INFO"); + } + case "R" -> { + clip.setMicrosecondPosition(0); + LogHandler.write("Music reseted", "INFO"); + } default -> System.out.println("try again"); } - System.out.println("You stoped the Audio element"); + System.out.println("You stopped the Audio element"); } clip.close(); diff --git a/src/main/java/musichub/main/Main.java b/src/main/java/musichub/main/Main.java index 4ac7052..07786d9 100644 --- a/src/main/java/musichub/main/Main.java +++ b/src/main/java/musichub/main/Main.java @@ -54,6 +54,7 @@ public class Main { List songs = theHub.getAlbumSongsSortedByGenre(albumTitle); System.out.println(songs); } catch (NoAlbumFoundException ex) { + LogHandler.write("No album found with the requested title", "WARNING"); System.out.println("No album found with the requested title " + ex.getMessage()); } printAvailableCommands(); @@ -71,6 +72,7 @@ public class Main { String song = scan.nextLine(); theHub.getAudioElement(songs, song); } catch (NoAlbumFoundException ex) { + LogHandler.write("No album found with the requested title", "WARNING"); System.out.println("No album found with the requested title " + ex.getMessage()); } printAvailableCommands(); @@ -121,6 +123,7 @@ public class Main { System.out.println("New element list: "); Iterator it = theHub.elements(); while (it.hasNext()) System.out.println(it.next().getTitle()); + LogHandler.write("Song successfully created", "INFO"); System.out.println("Song created!"); printAvailableCommands(); choice = scan.nextLine(); @@ -141,6 +144,7 @@ public class Main { System.out.println("New list of albums: "); Iterator ita = theHub.albums(); while (ita.hasNext()) System.out.println(ita.next().getTitle()); + LogHandler.write("Album successfully created", "INFO"); System.out.println("Album created!"); printAvailableCommands(); choice = scan.nextLine(); @@ -168,6 +172,7 @@ public class Main { } catch (NoAlbumFoundException | NoElementFoundException ex) { System.out.println(ex.getMessage()); } + LogHandler.write("Song successfully added to the album", "INFO"); System.out.println("Song added to the album!"); printAvailableCommands(); choice = scan.nextLine(); @@ -189,6 +194,7 @@ public class Main { String bLanguage = scan.nextLine(); AudioBook b = new AudioBook(bTitle, bArtist, bLength, bContent, bLanguage, bCategory); theHub.addElement(b); + LogHandler.write("Audiobook successfully created", "INFO"); System.out.println("Audiobook created! New element list: "); Iterator itl = theHub.elements(); while (itl.hasNext()) System.out.println(itl.next().getTitle()); @@ -227,6 +233,7 @@ public class Main { System.out.println("Type y to add a new one, n to end"); choice = scan.nextLine(); } + LogHandler.write("Playlist successfully created", "INFO"); System.out.println("Playlist created!"); printAvailableCommands(); choice = scan.nextLine(); @@ -245,6 +252,7 @@ public class Main { } catch (NoPlayListFoundException ex) { System.out.println(ex.getMessage()); } + LogHandler.write("Playlist successfully deleted", "INFO"); System.out.println("Playlist deleted!"); printAvailableCommands(); choice = scan.nextLine(); @@ -254,6 +262,7 @@ public class Main { theHub.saveElements(); theHub.saveAlbums(); theHub.savePlayLists(); + LogHandler.write("Elements, albums and playlists successfully saved", "INFO"); System.out.println("Elements, albums and playlists saved!"); printAvailableCommands(); choice = scan.nextLine(); @@ -267,9 +276,11 @@ public class Main { System.err.println(e.getMessage()); } catch (java.io.FileNotFoundException e){ - System.err.println(e.getMessage()+" Please create a file with the extension .wav inside the song folder at root of the app"); + LogHandler.write("Please create a file with the extension .wav inside the song folder at root of the app", "ERROR"); + System.err.println(e.getMessage() + " Please create a file with the extension .wav inside the song folder at root of the app"); } printAvailableCommands(); + choice = scan.nextLine(); break; case 'o': //consult the app logs @@ -289,6 +300,7 @@ public class Main { String song = scan.nextLine(); theHub.getAudioElement(songs, song); } catch (NoPlayListFoundException ex) { + LogHandler.write("No playlist found with the requested title", "WARNING"); System.out.println("No playlist found with the requested title " + ex.getMessage()); } printAvailableCommands(); diff --git a/src/main/java/musichub/util/Policy.java b/src/main/java/musichub/util/Policy.java index 67a1c40..ac067b4 100644 --- a/src/main/java/musichub/util/Policy.java +++ b/src/main/java/musichub/util/Policy.java @@ -1,5 +1,6 @@ package musichub.util; +import java.io.IOException; import java.util.Scanner; /** @@ -104,6 +105,11 @@ public final class Policy { } } } + try { + LogHandler.write("Terms accepted by the user.", "INFO"); + } catch (IOException e) { + e.printStackTrace(); + } } /** -- cgit v1.2.3