Implemented logging

Also fixed a minor issue where the configuration HashMap was not initialized and threw a NullPointerException.
This commit is contained in:
Alix von Schirp
2023-01-18 02:26:48 +01:00
parent e326867ebd
commit ee41a0e417
4 changed files with 21 additions and 4 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
# Project exclude paths # Project exclude paths
/target/ /target/
.idea/

View File

@@ -15,12 +15,15 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.HashMap; import java.util.HashMap;
import static de.b00tload.tools.lastfmtospotifyplaylist.util.Logger.logLn;
public class LastFMToSpotify { public class LastFMToSpotify {
public static final String LINE_SEPERATOR = System.getProperty("line.separator"); public static final String LINE_SEPERATOR = System.getProperty("line.separator");
public static HashMap<String, String> configuration; public static HashMap<String, String> configuration;
public static void main(String[] args) { public static void main(String[] args) {
configuration = new HashMap<>();
configuration.put("requests.useragent", "LastFMToSpotify/1.0-Snapshot (" + System.getProperty("os.name") + "; " + System.getProperty("os.arch") + ") Java/"+System.getProperty("java.version")); configuration.put("requests.useragent", "LastFMToSpotify/1.0-Snapshot (" + System.getProperty("os.name") + "; " + System.getProperty("os.arch") + ") Java/"+System.getProperty("java.version"));
for(int a = 0; a<args.length; a++){ for(int a = 0; a<args.length; a++){
Arguments arg; Arguments arg;
@@ -44,6 +47,11 @@ public class LastFMToSpotify {
} }
} }
logLn("Priority 0",0 );
logLn("Priority 1",1 );
logLn("Priority 2",2 );
logLn("Priority 3",3 );
// Start Progress Bar // Start Progress Bar
try (ProgressBar pb = new ProgressBar("LastFM -> Spotify Playlist", 4)) { try (ProgressBar pb = new ProgressBar("LastFM -> Spotify Playlist", 4)) {
for (int progress = 1; progress<=5; progress++) { for (int progress = 1; progress<=5; progress++) {

View File

@@ -53,7 +53,13 @@ public class ArgumentHandler {
} }
private static void verbose(String value){ private static void verbose(String value){
//wenn value != int try {
System.out.println("LogLevel must be a numeric value."); int loglevel = Integer.parseInt(value);
configuration.put("logging.level", String.valueOf(loglevel));
} catch (NumberFormatException e) {
System.out.println("LogLevel must be a numeric value.");
System.exit(500);
}
} }
} }

View File

@@ -5,7 +5,9 @@ import static de.b00tload.tools.lastfmtospotifyplaylist.LastFMToSpotify.configur
public class Logger { public class Logger {
public static void logLn(String string, int priority){ public static void logLn(String string, int priority){
if(Integer.parseInt(configuration.get("verbose.level"))) if(Integer.parseInt(configuration.get("logging.level"))>=priority){
System.out.println(string);
}
} }
} }