From 402491949b2731b02f6dce0e0dbeedded94abbf9 Mon Sep 17 00:00:00 2001 From: aj Date: Thu, 2 May 2019 15:14:24 +0100 Subject: [PATCH] logging to correct list, fixed return types --- .../java/sarsoo/fmframework/fm/FmNetwork.java | 44 +++++++++---------- .../sarsoo/fmframework/fm/FmUserNetwork.java | 4 +- .../fmframework/log/entry/ErrorEntry.java | 11 +++++ .../fmframework/log/entry/InfoEntry.java | 11 +++++ .../fmframework/log/entry/LogEntry.java | 5 --- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/main/java/sarsoo/fmframework/fm/FmNetwork.java b/src/main/java/sarsoo/fmframework/fm/FmNetwork.java index 7877f73..1eef2b2 100644 --- a/src/main/java/sarsoo/fmframework/fm/FmNetwork.java +++ b/src/main/java/sarsoo/fmframework/fm/FmNetwork.java @@ -2,7 +2,6 @@ package sarsoo.fmframework.fm; import sarsoo.fmframework.log.Log; import sarsoo.fmframework.log.Logger; -import sarsoo.fmframework.log.console.ConsoleHandler; import sarsoo.fmframework.log.entry.ErrorEntry; import sarsoo.fmframework.log.entry.InfoEntry; import sarsoo.fmframework.log.entry.LogEntry; @@ -77,31 +76,32 @@ public class FmNetwork { try { builder.setMbid(albumJson.getString("mbid")); } catch (JSONException e) { - log.log(new InfoEntry("getAlbum").addArg("no mbid for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getAlbum").addArg("no mbid for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setUrl(albumJson.getString("url")); } catch (JSONException e) { - log.log(new InfoEntry("getAlbum").addArg("no url for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getAlbum").addArg("no url for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setListeners(albumJson.getInt("listeners")); } catch (JSONException e) { - log.log(new InfoEntry("getAlbum").addArg("no listeners for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getAlbum").addArg("no listeners for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setPlayCount(albumJson.getInt("playcount")); } catch (JSONException e) { - log.log(new InfoEntry("getAlbum").addArg("no play count for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo( + new InfoEntry("getAlbum").addArg("no play count for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setUserPlayCount(albumJson.getInt("userplaycount")); } catch (JSONException e) { - log.log(new InfoEntry("getAlbum").addArg("no user play count for").addArg(nameIn) + log.logInfo(new InfoEntry("getAlbum").addArg("no user play count for").addArg(nameIn) .addArg(e.getMessage())); } @@ -114,13 +114,13 @@ public class FmNetwork { builder.setWiki(wiki); } catch (JSONException e) { - log.log(new InfoEntry("getAlbum").addArg("no wiki for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getAlbum").addArg("no wiki for").addArg(nameIn).addArg(e.getMessage())); } return builder.build(); } catch (JSONException e) { - log.log(new InfoEntry("getAlbum").addArg("album name not found").addArg(e.getMessage())); + log.logInfo(new InfoEntry("getAlbum").addArg("album name not found").addArg(e.getMessage())); } return null; @@ -160,33 +160,33 @@ public class FmNetwork { try { builder.setMbid(artistJson.getString("mbid")); } catch (JSONException e) { - log.log(new InfoEntry("getArtist").addArg("no mbid for").addArg(artistName).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getArtist").addArg("no mbid for").addArg(artistName).addArg(e.getMessage())); } try { builder.setUrl(artistJson.getString("url")); } catch (JSONException e) { - log.log(new InfoEntry("getArtist").addArg("no url for").addArg(artistName).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getArtist").addArg("no url for").addArg(artistName).addArg(e.getMessage())); } try { builder.setListeners(artistJson.getJSONObject("stats").getInt("listeners")); } catch (JSONException e) { - log.log(new InfoEntry("getArtist").addArg("no listeners for").addArg(artistName) + log.logInfo(new InfoEntry("getArtist").addArg("no listeners for").addArg(artistName) .addArg(e.getMessage())); } try { builder.setPlayCount(artistJson.getJSONObject("stats").getInt("playcount")); } catch (JSONException e) { - log.log(new InfoEntry("getArtist").addArg("no play count for").addArg(artistName) + log.logInfo(new InfoEntry("getArtist").addArg("no play count for").addArg(artistName) .addArg(e.getMessage())); } try { builder.setUserPlayCount(artistJson.getJSONObject("stats").getInt("userplaycount")); } catch (JSONException e) { - log.log(new InfoEntry("getArtist").addArg("no user play count for").addArg(artistName) + log.logInfo(new InfoEntry("getArtist").addArg("no user play count for").addArg(artistName) .addArg(e.getMessage())); } @@ -199,13 +199,13 @@ public class FmNetwork { builder.setWiki(wiki); } catch (JSONException e) { - log.log(new InfoEntry("getArtist").addArg("no wiki for").addArg(artistName).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getArtist").addArg("no wiki for").addArg(artistName).addArg(e.getMessage())); } return builder.build(); } catch (JSONException e) { - log.log(new InfoEntry("getArtist").addArg("artist name not found").addArg(e.getMessage())); + log.logInfo(new InfoEntry("getArtist").addArg("artist name not found").addArg(e.getMessage())); } return null; @@ -249,31 +249,31 @@ public class FmNetwork { try { builder.setMbid(trackJson.getString("mbid")); } catch (JSONException e) { - log.log(new InfoEntry("getTrack").addArg("no mbid for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getTrack").addArg("no mbid for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setUrl(trackJson.getString("url")); } catch (JSONException e) { - log.log(new InfoEntry("getTrack").addArg("no url for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getTrack").addArg("no url for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setListeners(trackJson.getInt("listeners")); } catch (JSONException e) { - log.log(new InfoEntry("getTrack").addArg("no listeners for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getTrack").addArg("no listeners for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setPlayCount(trackJson.getInt("playcount")); } catch (JSONException e) { - log.log(new InfoEntry("getTrack").addArg("no play count for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getTrack").addArg("no play count for").addArg(nameIn).addArg(e.getMessage())); } try { builder.setUserPlayCount(trackJson.getInt("userplaycount")); } catch (JSONException e) { - log.log(new InfoEntry("getTrack").addArg("no user play count for").addArg(nameIn) + log.logInfo(new InfoEntry("getTrack").addArg("no user play count for").addArg(nameIn) .addArg(e.getMessage())); } @@ -286,13 +286,13 @@ public class FmNetwork { builder.setWiki(wiki); } catch (JSONException e) { - log.log(new InfoEntry("getTrack").addArg("no wiki for").addArg(nameIn).addArg(e.getMessage())); + log.logInfo(new InfoEntry("getTrack").addArg("no wiki for").addArg(nameIn).addArg(e.getMessage())); } return builder.build(); } catch (JSONException e) { - log.log(new InfoEntry("getTrack").addArg("track name not found").addArg(e.getMessage())); + log.logInfo(new InfoEntry("getTrack").addArg("track name not found").addArg(e.getMessage())); } return null; diff --git a/src/main/java/sarsoo/fmframework/fm/FmUserNetwork.java b/src/main/java/sarsoo/fmframework/fm/FmUserNetwork.java index 5eeeab1..4a865a4 100644 --- a/src/main/java/sarsoo/fmframework/fm/FmUserNetwork.java +++ b/src/main/java/sarsoo/fmframework/fm/FmUserNetwork.java @@ -8,9 +8,7 @@ import java.util.HashMap; import org.json.JSONArray; import org.json.JSONObject; -import sarsoo.fmframework.log.Log; import sarsoo.fmframework.log.Logger; -import sarsoo.fmframework.log.console.ConsoleHandler; import sarsoo.fmframework.log.entry.InfoEntry; import sarsoo.fmframework.log.entry.LogEntry; import sarsoo.fmframework.music.Artist; @@ -297,7 +295,7 @@ public class FmUserNetwork extends FmNetwork { Artist artist = getArtist(artistJson.getString("name")); - Logger.getLog().log(new InfoEntry("Tag").addArg(tagName).addArg(artist.getName())); + Logger.getLog().logInfo(new InfoEntry("Tag").addArg(tagName).addArg(artist.getName())); list.add(artist); diff --git a/src/main/java/sarsoo/fmframework/log/entry/ErrorEntry.java b/src/main/java/sarsoo/fmframework/log/entry/ErrorEntry.java index 679012d..87ec4bc 100644 --- a/src/main/java/sarsoo/fmframework/log/entry/ErrorEntry.java +++ b/src/main/java/sarsoo/fmframework/log/entry/ErrorEntry.java @@ -1,5 +1,7 @@ package sarsoo.fmframework.log.entry; +import java.util.ArrayList; + public class ErrorEntry extends LogEntry { protected int errorCode; @@ -12,6 +14,15 @@ public class ErrorEntry extends LogEntry { errorCode = error; return this; } + + @Override + public ErrorEntry addArg(String arg) { + if (args == null) { + args = new ArrayList(); + } + args.add(arg); + return this; + } public String toString() { diff --git a/src/main/java/sarsoo/fmframework/log/entry/InfoEntry.java b/src/main/java/sarsoo/fmframework/log/entry/InfoEntry.java index 5046062..a495e53 100644 --- a/src/main/java/sarsoo/fmframework/log/entry/InfoEntry.java +++ b/src/main/java/sarsoo/fmframework/log/entry/InfoEntry.java @@ -1,10 +1,21 @@ package sarsoo.fmframework.log.entry; +import java.util.ArrayList; + public class InfoEntry extends LogEntry { public InfoEntry(String methodIn) { super(methodIn); } + + @Override + public InfoEntry addArg(String arg) { + if (args == null) { + args = new ArrayList(); + } + args.add(arg); + return this; + } public String toString() { diff --git a/src/main/java/sarsoo/fmframework/log/entry/LogEntry.java b/src/main/java/sarsoo/fmframework/log/entry/LogEntry.java index 39446c9..bcbfb63 100644 --- a/src/main/java/sarsoo/fmframework/log/entry/LogEntry.java +++ b/src/main/java/sarsoo/fmframework/log/entry/LogEntry.java @@ -22,11 +22,6 @@ public class LogEntry { return args; } - public LogEntry setArgs(ArrayList argsIn) { - args = argsIn; - return this; - } - public LocalDateTime getTimeStamp() { return timestamp; }