I am trying to discover some simple and efficient way to use Android logger.
It give us deep information about error:
L.e("Test mesage");
com.yourpackage.ClassName: [Method] Test mesage
Stackoverflow pros/cons
import android.util.Log;
public class L
{
private enum LogState
{
INFO, ERROR, ALL;
}
public static final LogState CURRENT_STATE = LogState.ALL;
public static void e(final String msg)
{
switch (CURRENT_STATE)
{
case ALL:
case ERROR:
final Throwable t = new Throwable();
final StackTraceElement[] elements = t.getStackTrace();
final String callerClassName = elements[1].getClassName();
final String callerMethodName = elements[1].getMethodName();
Log.e(callerClassName, "[" + callerMethodName + "] " + msg);
}
}
public static void i(final String msg)
{
switch (CURRENT_STATE)
{
case ALL:
case INFO:
final Throwable t = new Throwable();
final StackTraceElement[] elements = t.getStackTrace();
final String callerClassName = elements[1].getClassName();
final String callerMethodName = elements[1].getMethodName();
Log.d(callerClassName, "[" + callerMethodName + "] " + msg);
}
}
}
1 Comment
Great using throwable :)