logging to correct list, fixed return types

This commit is contained in:
aj 2019-05-02 15:14:24 +01:00
parent 0ecc01c1be
commit 402491949b
5 changed files with 45 additions and 30 deletions

View File

@ -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;

View File

@ -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);

View File

@ -1,5 +1,7 @@
package sarsoo.fmframework.log.entry;
import java.util.ArrayList;
public class ErrorEntry extends LogEntry {
protected int errorCode;
@ -13,6 +15,15 @@ public class ErrorEntry extends LogEntry {
return this;
}
@Override
public ErrorEntry addArg(String arg) {
if (args == null) {
args = new ArrayList<String>();
}
args.add(arg);
return this;
}
public String toString() {
String logString = String.format("%s !!%s", timestamp, method);

View File

@ -1,11 +1,22 @@
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<String>();
}
args.add(arg);
return this;
}
public String toString() {
String logString = String.format("%s \t>%s", timestamp, method);

View File

@ -22,11 +22,6 @@ public class LogEntry {
return args;
}
public LogEntry setArgs(ArrayList<String> argsIn) {
args = argsIn;
return this;
}
public LocalDateTime getTimeStamp() {
return timestamp;
}