提交 b5d030c9 编写于 作者: B Blankj

see 04/10 log

上级 46a5a9c0
......@@ -41,7 +41,7 @@
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.9-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.10-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.9-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.13.10-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
......
......@@ -66,21 +66,15 @@ public class UtilsApp extends BaseApplication {
.setConsoleFilter(LogUtils.V)// log 的控制台过滤器,和 logcat 过滤器同理,默认 Verbose
.setFileFilter(LogUtils.V)// log 文件过滤器,和 logcat 过滤器同理,默认 Verbose
.setStackDeep(1);// log 栈深度,默认为 1
new Thread(new Runnable() {
@Override
public void run() {
LogUtils.d(config.toString());
}
}).start();
LogUtils.d(config.toString());
}
@SuppressLint("MissingPermission")
private void initCrash() {
CrashUtils.init(new CrashUtils.OnCrashListener() {
@Override
public void onCrash(Throwable e) {
e.printStackTrace();
public void onCrash(String crashInfo, Throwable e) {
LogUtils.e(crashInfo);
restartApp();
}
});
......
......@@ -33,8 +33,8 @@ ext {
min_sdk_version = 14
target_sdk_version = 27
version_code = 1_013_009
version_name = '1.13.9'// E.g 1.9.72 => 1,009,072
version_code = 1_013_010
version_name = '1.13.10'// E.g 1.9.72 => 1,009,072
// App dependencies
support_version = '27.1.0'
......
* 18/04/10 完善 OnCrashListener 回调崩溃信息,发布 1.13.10 版本
* 18/04/09 修复静默安装重载错误,发布 1.13.9 版本
* 18/04/08 修复获取栈顶 Activity 链表为空的异常,获取栈顶 Activity 放到 Utils 中,发布 1.13.8 版本
* 18/04/06 新增 GsonUtils 及单元测试
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
compile 'com.blankj:utilcode:1.13.9'
compile 'com.blankj:utilcode:1.13.10'
```
......
......@@ -2,7 +2,7 @@
Gradle:
```groovy
compile 'com.blankj:utilcode:1.13.9'
compile 'com.blankj:utilcode:1.13.10'
```
......
......@@ -8,10 +8,12 @@ import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresPermission;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.Thread.UncaughtExceptionHandler;
import java.text.Format;
import java.text.SimpleDateFormat;
......@@ -85,9 +87,21 @@ public final class CrashUtils {
}
return;
}
if (sOnCrashListener != null) {
sOnCrashListener.onCrash(e);
StringBuilder sb = new StringBuilder();
sb.append(CRASH_HEAD);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Throwable cause = e.getCause();
while (cause != null) {
cause.printStackTrace(pw);
cause = cause.getCause();
}
pw.flush();
sb.append(sw.toString());
final String crashInfo = sb.toString();
Date now = new Date(System.currentTimeMillis());
String fileName = FORMAT.format(now) + ".txt";
final String fullPath = (dir == null ? defaultDir : dir) + fileName;
......@@ -98,25 +112,28 @@ public final class CrashUtils {
sExecutor.execute(new Runnable() {
@Override
public void run() {
PrintWriter pw = null;
BufferedWriter bw = null;
try {
pw = new PrintWriter(new FileWriter(fullPath, false));
pw.write(CRASH_HEAD);
e.printStackTrace(pw);
Throwable cause = e.getCause();
while (cause != null) {
cause.printStackTrace(pw);
cause = cause.getCause();
}
bw = new BufferedWriter(new FileWriter(fullPath, false));
bw.write(crashInfo);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (pw != null) {
pw.close();
if (bw != null) {
try {
bw.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
});
if (sOnCrashListener != null) {
sOnCrashListener.onCrash(crashInfo, e);
}
if (DEFAULT_UNCAUGHT_EXCEPTION_HANDLER != null) {
DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(t, e);
}
......@@ -239,6 +256,6 @@ public final class CrashUtils {
}
public interface OnCrashListener {
void onCrash(Throwable e);
void onCrash(String crashInfo, Throwable e);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册