Perhaps having come languages like PHP, Javascript or ActionScript, I just can not get used to tagging log output.
Hence I came up with a class: OneLog – one tag.
public class OneLog { | |
public static String TAG = OneLog.class.getName(); | |
private OneLog() { | |
} | |
public static int v(String msg) { | |
return android.util.Log.v(TAG, msg); | |
} | |
public static int v(String msg, Throwable tr) { | |
return android.util.Log.v(TAG, msg, tr); | |
} | |
public static int d(String msg) { | |
return android.util.Log.d(TAG, msg); | |
} | |
public static int d(String msg, Throwable tr) { | |
return android.util.Log.d(TAG, msg, tr); | |
} | |
public static int i(String msg) { | |
return android.util.Log.i(TAG, msg); | |
} | |
public static int i(String msg, Throwable tr) { | |
return android.util.Log.i(TAG, msg, tr); | |
} | |
public static int w(String msg) { | |
return android.util.Log.w(TAG, msg); | |
} | |
public static int w(String msg, Throwable tr) { | |
return android.util.Log.w(TAG, msg, tr); | |
} | |
public static int w(Throwable tr) { | |
return android.util.Log.w(TAG, tr); | |
} | |
public static int e(String msg) { | |
return android.util.Log.e(TAG, msg); | |
} | |
public static int e(String msg, Throwable tr) { | |
return android.util.Log.e(TAG, msg, tr); | |
} | |
} |
I initialise OneLog.TAG in my Application class, but it really can go anywhere appropriate.
1 2 3 4 5 6 7 8 9 | public class MyApp extends Application { public static final String PACKAGE; static { PACKAGE = MyApp. class .getPackage().getName(); OneLog.TAG = PACKAGE; } ... } |
And then you’re free (from tagging):
1 | Log.i("test log"); |