mirror of
https://github.com/bilde2910/Hauk.git
synced 2026-01-23 02:24:09 +00:00
Add more detailed logging
This commit is contained in:
parent
d6c338611d
commit
539bc6940e
6 changed files with 47 additions and 32 deletions
|
|
@ -68,7 +68,8 @@ public enum Constants {
|
|||
public static final String REGEX_ADOPT_ID_FROM_LINK = "\\?([A-Za-z0-9-]+)";
|
||||
|
||||
// Formatting and input validation.
|
||||
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss z";
|
||||
public static final String DATE_FORMAT_UI = "yyyy-MM-dd HH:mm:ss z";
|
||||
public static final String DATE_FORMAT_LOG = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
|
||||
public static final int PORT_MIN = 0;
|
||||
public static final int PORT_MAX = 65536;
|
||||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ public abstract class SessionManager {
|
|||
// Called when sharing ends. Clear the active session, and all collections of active
|
||||
// shares present in this class, then propagate this stop message upstream to all
|
||||
// session listeners.
|
||||
Log.d("Performing stop task cleanup for task %s and stopping timed callback on handler %s", this, SessionManager.this.handler); //NON-NLS
|
||||
SessionManager.this.activeSession = null;
|
||||
SessionManager.this.handler.removeCallbacksAndMessages(null);
|
||||
SessionManager.this.resumable.clearResumableSession();
|
||||
|
|
@ -195,10 +196,12 @@ public abstract class SessionManager {
|
|||
// be created and attached when creating a new SessionManager in MainActivity. There is
|
||||
// probably a cleaner way to do this.
|
||||
if (pusher != null) {
|
||||
Log.d("Pusher is non-null (%s), stopping and nulling it and calling service relauncher", pusher); //NON-NLS
|
||||
this.ctx.stopService(pusher);
|
||||
pusher = null;
|
||||
this.resumable.tryResumeShare(new ServiceRelauncher(this, this.resumable));
|
||||
} else {
|
||||
Log.d("Pusher is null, calling resumption prompter"); //NON-NLS
|
||||
this.resumable.tryResumeShare(new AutoResumptionPrompter(this, this.resumable, prompt));
|
||||
}
|
||||
}
|
||||
|
|
@ -402,13 +405,14 @@ public abstract class SessionManager {
|
|||
this.stopTask.updateTask(pusher);
|
||||
|
||||
// Required for session relaunches
|
||||
Log.d("Setting static pusher %s (was %s)", pusher, SessionManager.pusher); //NON-NLS
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
SessionManager.pusher = pusher;
|
||||
|
||||
// stopTask is scheduled for expiration, but it could also be called if the user
|
||||
// manually stops the share, or if the app is destroyed.
|
||||
long expireIn = share.getSession().getRemainingMillis();
|
||||
Log.i("Scheduling session expiration in %s milliseconds", expireIn); //NON-NLS
|
||||
Log.i("Scheduling session task %s for expiration in %s milliseconds on handler %s", this.stopTask, expireIn, this.handler); //NON-NLS
|
||||
this.handler.postDelayed(this.stopTask, expireIn);
|
||||
|
||||
// Push the start event to upstream listeners.
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public abstract class StopSharingTask implements Runnable {
|
|||
* @param pusher A location handler that should be unregistered when sharing is stopped.
|
||||
*/
|
||||
final void updateTask(Intent pusher) {
|
||||
Log.i("Setting new update task"); //NON-NLS
|
||||
Log.i("Setting new update task %s in task %s", pusher, this); //NON-NLS
|
||||
this.pusher = pusher;
|
||||
this.canExecute = true;
|
||||
}
|
||||
|
|
@ -93,6 +93,7 @@ public abstract class StopSharingTask implements Runnable {
|
|||
*/
|
||||
@Override
|
||||
public final void run() {
|
||||
Log.d("Stop sharing task %s was called", this); //NON-NLS
|
||||
if (!this.canExecute) return;
|
||||
Log.i("Executing share stop task"); //NON-NLS
|
||||
this.canExecute = false;
|
||||
|
|
|
|||
|
|
@ -108,6 +108,8 @@ public final class LocationPushService extends Service {
|
|||
GNSSActiveHandler parentHandler = (GNSSActiveHandler) ReceiverDataRegistry.retrieve(intent.getIntExtra(Constants.EXTRA_GNSS_ACTIVE_TASK, -1));
|
||||
this.handler = (Handler) ReceiverDataRegistry.retrieve(intent.getIntExtra(Constants.EXTRA_HANDLER, -1));
|
||||
|
||||
Log.d("Pusher was given extras stopTask=%s, share=%s, parentHandler=%s, handler=%s", stopTask, this.share, parentHandler, this.handler); //NON-NLS
|
||||
|
||||
try {
|
||||
// Even though we previously requested location permission, we still have to check for
|
||||
// it when we actually use the location API.
|
||||
|
|
@ -150,7 +152,7 @@ public final class LocationPushService extends Service {
|
|||
this.listenFine.onStopped();
|
||||
this.locMan.removeUpdates(this.listenFine);
|
||||
|
||||
Log.i("Removing callbacks from handler"); //NON-NLS
|
||||
Log.i("Removing callbacks from handler %s", this.handler); //NON-NLS
|
||||
this.handler.removeCallbacksAndMessages(null);
|
||||
this.gnssActiveTask = new MultiTargetGNSSHandlerProxy();
|
||||
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public final class Session implements Serializable {
|
|||
* Returns the expiration time of this session as a human-readable string.
|
||||
*/
|
||||
public String getExpiryString() {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(Constants.DATE_FORMAT, Locale.getDefault());
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(Constants.DATE_FORMAT_UI, Locale.getDefault());
|
||||
return formatter.format(getExpiryDate());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
package info.varden.hauk.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import info.varden.hauk.BuildConfig;
|
||||
import info.varden.hauk.Constants;
|
||||
|
||||
/**
|
||||
* Log wrapper to simplify logging in Hauk.
|
||||
|
|
@ -13,14 +18,16 @@ public enum Log {
|
|||
private static final int STACK_DEPTH = 4;
|
||||
|
||||
/**
|
||||
* Returns the caller of the log function.
|
||||
* Returns the timestamp and caller of the log function.
|
||||
*/
|
||||
private static String getCaller() {
|
||||
private static String getLogPrefix() {
|
||||
String timestamp = new SimpleDateFormat(Constants.DATE_FORMAT_LOG, Locale.US).format(new Date());
|
||||
|
||||
String caller = Thread.currentThread().getStackTrace()[STACK_DEPTH].toString();
|
||||
if (caller.startsWith(BuildConfig.APPLICATION_ID)) {
|
||||
caller = caller.substring(BuildConfig.APPLICATION_ID.length());
|
||||
}
|
||||
return caller;
|
||||
return timestamp + ": " + caller + ": ";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,98 +44,98 @@ public enum Log {
|
|||
}
|
||||
|
||||
public static void e(String msg) {
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg);
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getLogPrefix() + msg);
|
||||
}
|
||||
|
||||
public static void e(String msg, Object... args) {
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)));
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)));
|
||||
}
|
||||
|
||||
public static void e(String msg, Throwable tr) {
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg, tr);
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getLogPrefix() + msg, tr);
|
||||
}
|
||||
|
||||
public static void e(String msg, Throwable tr, Object... args) {
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)), tr);
|
||||
android.util.Log.e(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)), tr);
|
||||
}
|
||||
|
||||
public static void w(String msg) {
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg);
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getLogPrefix() + msg);
|
||||
}
|
||||
|
||||
public static void w(String msg, Object... args) {
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)));
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)));
|
||||
}
|
||||
|
||||
public static void w(String msg, Throwable tr) {
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg, tr);
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getLogPrefix() + msg, tr);
|
||||
}
|
||||
|
||||
public static void w(String msg, Throwable tr, Object... args) {
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)), tr);
|
||||
android.util.Log.w(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)), tr);
|
||||
}
|
||||
|
||||
public static void i(String msg) {
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg);
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getLogPrefix() + msg);
|
||||
}
|
||||
|
||||
public static void i(String msg, Object... args) {
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)));
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)));
|
||||
}
|
||||
|
||||
public static void i(String msg, Throwable tr) {
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg, tr);
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getLogPrefix() + msg, tr);
|
||||
}
|
||||
|
||||
public static void i(String msg, Throwable tr, Object... args) {
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)), tr);
|
||||
android.util.Log.i(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)), tr);
|
||||
}
|
||||
|
||||
public static void v(String msg) {
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg);
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getLogPrefix() + msg);
|
||||
}
|
||||
|
||||
public static void v(String msg, Object... args) {
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)));
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)));
|
||||
}
|
||||
|
||||
public static void v(String msg, Throwable tr) {
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg, tr);
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getLogPrefix() + msg, tr);
|
||||
}
|
||||
|
||||
public static void v(String msg, Throwable tr, Object... args) {
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)), tr);
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)), tr);
|
||||
}
|
||||
|
||||
public static void d(String msg) {
|
||||
android.util.Log.d(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg);
|
||||
android.util.Log.d(BuildConfig.APPLICATION_ID, getLogPrefix() + msg);
|
||||
}
|
||||
|
||||
public static void d(String msg, Object... args) {
|
||||
android.util.Log.d(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)));
|
||||
android.util.Log.d(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)));
|
||||
}
|
||||
|
||||
public static void d(String msg, Throwable tr) {
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg, tr);
|
||||
android.util.Log.v(BuildConfig.APPLICATION_ID, getLogPrefix() + msg, tr);
|
||||
}
|
||||
|
||||
public static void d(String msg, Throwable tr, Object... args) {
|
||||
android.util.Log.d(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)), tr);
|
||||
android.util.Log.d(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)), tr);
|
||||
}
|
||||
|
||||
public static void wtf(String msg) {
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg);
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getLogPrefix() + msg);
|
||||
}
|
||||
|
||||
public static void wtf(String msg, Object... args) {
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)));
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)));
|
||||
}
|
||||
|
||||
public static void wtf(String msg, Throwable tr) {
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getCaller() + ": " + msg, tr);
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getLogPrefix() + msg, tr);
|
||||
}
|
||||
|
||||
public static void wtf(String msg, Throwable tr, Object... args) {
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getCaller() + ": " + String.format(msg, argsToStrings(args)), tr);
|
||||
android.util.Log.wtf(BuildConfig.APPLICATION_ID, getLogPrefix() + String.format(msg, argsToStrings(args)), tr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue