How does Log.wtf() differ from Log.e()?

前端 未结 7 599
臣服心动
臣服心动 2020-12-13 12:18

I have looked at the documentation for android.util.Log and I\'m not sure exactly what the difference between Log.e() and Log.wtf() is. Is one pref

相关标签:
7条回答
  • 2020-12-13 12:36

    Actually, this might be a documentation error in Android SDK, what a surprise... Doc says:

    The error will always be logged at level ASSERT with the call stack.

    But source code says this:

    static int wtf(int logId, String tag, String msg, Throwable tr, boolean localStack, boolean system) {
    
        ...
    
        int bytes = printlns(logId, ERROR, tag, msg, localStack ? what : tr);
    
        ...
    }
    

    So, Log.wtf() and Log.e() both have the same priority, ERROR.

    The difference is that Log.wtf() calls for onTerribleFailure() call back, which "Report a serious error in the current process. May or may not cause the process to terminate (depends on system settings)."

    So, in other words, Log.wtf() could crash your app.

    Below is a code snippet:

    if (ActivityManager.getService().handleApplicationWtf(
            mApplicationObject, tag, system,
            new ApplicationErrorReport.ParcelableCrashInfo(t))) {
      // The Activity Manager has already written us off -- now exit.
      Process.killProcess(Process.myPid());
      System.exit(10);
    }
    
    0 讨论(0)
提交回复
热议问题