Log Exception trace : Log « Core Class « Android






Log Exception trace

    

class Log {
  public static final String TAG = "tag";

  public static void debug(String tag, String content) {
    StackTraceElement[] trace = new Throwable().getStackTrace();
    String msg = "";

    if (trace.length >= 1) {
      StackTraceElement elt = trace[1];
      msg = "[" + elt.getFileName() + " Line:" + elt.getLineNumber()
          + "] " + elt.getMethodName() + " " + content;
      android.util.Log.i(tag, msg);
    } else {
      android.util.Log.i(tag, msg);
    }
  }

  public static void error(String tag, String content) {
    StackTraceElement[] trace = new Throwable().getStackTrace();
    String msg = "";

    if (trace.length >= 1) {
      StackTraceElement elt = trace[1];
      msg = "[" + elt.getFileName() + " Line:" + elt.getLineNumber()
          + "] " + elt.getMethodName() + " " + content;
      android.util.Log.e(tag, msg);
    } else {
      android.util.Log.e(tag, msg);
    }
  }
}

   
    
    
    
  








Related examples in the same category

1.Use log
2.Log Utility
3.Log events
4.Log your action
5.Write an activity that looks like a pop-up dialog with a custom theme using a different text color.
6.Responsible for delegating calls to the Android logging system.
7.Dynamically defined), space efficient event logging to help instrument code for large scale stability and performance monitoring.
8.Write Exception Stack to Log
9.Logger and Logger Listener
10.Log a list of objects
11.Utility log tool
12.Debug Util