1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-25 13:52:08 +01:00

Fixed a lint issue and caught potential null pointers in AppLog

This commit is contained in:
vanitasvitae 2016-11-06 16:45:21 +01:00
parent 73cb775af2
commit 825d9be1e0
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615

View file

@ -18,6 +18,7 @@
*/ */
package com.github.dfa.diaspora_android.util; package com.github.dfa.diaspora_android.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -25,6 +26,7 @@ import java.util.Observable;
import java.util.Observer; import java.util.Observer;
/** /**
* Class that logs debug messages to Androids Log and to additional targets (like textviews)
* Created by gregor on 18.09.16. * Created by gregor on 18.09.16.
*/ */
public class AppLog { public class AppLog {
@ -59,37 +61,61 @@ public class AppLog {
*/ */
public static void v(Object source, String _text) { public static void v(Object source, String _text) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
Log.v(getLogPrefix(source), _text); if(source != null) {
Log.v(getLogPrefix(source), _text);
} else {
Log.v("null", _text);
}
} }
} }
public static void i(Object source, String _text) { public static void i(Object source, String _text) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
Log.i(getLogPrefix(source), _text); if(source != null) {
Log.i(getLogPrefix(source), _text);
} else {
Log.i("null", _text);
}
} }
} }
public static void d(Object source, String _text) { public static void d(Object source, String _text) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
Log.d(getLogPrefix(source), _text); if(source != null) {
Log.d(getLogPrefix(source), _text);
} else {
Log.d("null", _text);
}
} }
} }
public static void e(Object source, String _text) { public static void e(Object source, String _text) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
Log.e(getLogPrefix(source), _text); if(source != null) {
Log.e(getLogPrefix(source), _text);
} else {
Log.e("null", _text);
}
} }
} }
public static void w(Object source, String _text) { public static void w(Object source, String _text) {
if (isLoggingEnabled()) { if (isLoggingEnabled()) {
Log.w(getLogPrefix(source), _text); if(source != null) {
Log.w(getLogPrefix(source), _text);
} else {
Log.w("null", _text);
}
} }
} }
public static void spam(Object source, String _text) { public static void spam(Object source, String _text) {
if (isLoggingEnabled() && isLoggingSpamEnabled()) { if (isLoggingEnabled() && isLoggingSpamEnabled()) {
Log.v(getLogPrefix(source), _text); if(source != null) {
Log.v(getLogPrefix(source), _text);
} else {
Log.v("null", _text);
}
} }
} }
@ -103,7 +129,7 @@ public class AppLog {
public static Log instance; public static Log instance;
private AppSettings appSettings; private AppSettings appSettings;
private SimpleDateFormat dateFormat; private DateFormat dateFormat;
private ArrayList<String> logBuffer; private ArrayList<String> logBuffer;
private ArrayList<Observer> observers; private ArrayList<Observer> observers;
@ -118,7 +144,8 @@ public class AppLog {
} else { } else {
logBuffer = new ArrayList<>(); logBuffer = new ArrayList<>();
} }
dateFormat = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat.getTimeInstance();
dateFormat = SimpleDateFormat.getDateInstance();
observers = new ArrayList<>(); observers = new ArrayList<>();
} }