e.printStackTrace()工作正常(即,将我的堆栈跟踪信息打印到stderr),但是Log.X根本无法打印堆栈跟踪信息。
例如:
} catch (IOException e) {
Log.e("Network", "Exception", e);
e.printStackTrace();
}
输出:
08-31 03:46:21.992: W/Network(13238): Exception
08-31 03:46:22.092: W/System.err(13238): java.net.UnknownHostException: Unable to resolve host "...": No address associated with hostname
08-31 03:46:22.204: W/System.err(13238): at java.net.InetAddress.lookupHostByName(InetAddress.java:394)
08-31 03:46:22.222: W/System.err(13238): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-31 03:46:22.222: W/System.err(13238): at java.net.InetAddress.getAllByName(InetAddress.java:214)
找出Log.X使用的Android Log.getStackTraceString吞下UnknownHostException。 :(
public static String getStackTraceString(Throwable tr) {
if (tr == null) {
return "";
}
// This is to reduce the amount of log spew that apps do in the non-error
// condition of the network being unavailable.
Throwable t = tr;
while (t != null) {
if (t instanceof UnknownHostException) {
return "";
}
t = t.getCause();
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
tr.printStackTrace(pw);
return sw.toString();
}
减少日志记录非常好,但是甚至不告诉我我的例外是糟糕的joojoo!
我也遇到这种问题,并创建了一个Xposed模块来克服此问题。有关安装说明,请参见Xposed for Android 8+或Original Xposed。后来我偶然发现了这个线程。
这里是项目:FullStackTrace
还有发行版的apk下载。
您的设备必须植根才能使用Xposed。我在这里使用Magisk。