Implemented logging
Also fixed a minor issue where the configuration HashMap was not initialized and threw a NullPointerException.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
# Project exclude paths
|
# Project exclude paths
|
||||||
/target/
|
/target/
|
||||||
|
.idea/
|
||||||
|
|||||||
@@ -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++) {
|
||||||
|
|||||||
@@ -53,7 +53,13 @@ public class ArgumentHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void verbose(String value){
|
private static void verbose(String value){
|
||||||
//wenn value != int
|
try {
|
||||||
|
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.out.println("LogLevel must be a numeric value.");
|
||||||
|
System.exit(500);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user