From 90e249e2d73f16d0746716336969fa37ddf1c002 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Fri, 21 Oct 2022 18:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=90=8E=E7=AB=AF=E9=9C=80?= =?UTF-8?q?=E6=B1=82=E4=BF=AE=E6=94=B9=E4=B8=8A=E6=8A=A5=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/shayu/phonelive/NeverCrashUtils.java | 7 +++- .../phonelive/activity/LauncherActivity.java | 2 +- .../java/com/yunbao/common/utils/LogUtil.java | 38 ++++++++++++++----- .../yunbao/main/activity/MainActivity.java | 1 - 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java index c5f677c5f..b36fe9f3d 100644 --- a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java +++ b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java @@ -1,10 +1,12 @@ package com.shayu.phonelive; + import android.app.Application; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.util.Log; import android.widget.Toast; + import com.yunbao.common.utils.FileUtil; import com.yunbao.common.utils.SpUtil; @@ -126,10 +128,11 @@ public class NeverCrashUtils { } private static String throwableToString(Throwable e) { StringWriter writer=new StringWriter(); - writer.write(SpUtil.getInstance().getStringValue(SpUtil.USER_INFO)); - writer.write("\n"); writer.write("time="+System.currentTimeMillis()); writer.write("\n"); + writer.write("UserData="); + writer.write(SpUtil.getInstance().getStringValue(SpUtil.USER_INFO)); + writer.write("\n"); writer.write("[ERROR]"); PrintWriter printWriter=new PrintWriter(writer); e.printStackTrace(printWriter); diff --git a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java index b67bb3bb4..d33b57031 100644 --- a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java +++ b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java @@ -139,7 +139,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL } }; mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000); - LogUtil.pushError(AppContext.sInstance); + LogUtil.uploadErrorLog(AppContext.sInstance); } diff --git a/common/src/main/java/com/yunbao/common/utils/LogUtil.java b/common/src/main/java/com/yunbao/common/utils/LogUtil.java index 8c52d9a82..154921391 100644 --- a/common/src/main/java/com/yunbao/common/utils/LogUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/LogUtil.java @@ -16,9 +16,8 @@ import com.yunbao.common.CommonAppConfig; import java.io.File; import java.io.FileWriter; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Created by cxf on 2019/6/20. @@ -46,20 +45,30 @@ public class LogUtil { } } } - public static void pushError(Context context){ - if(!CommonAppConfig.IS_UPLOAD_ERROR_LOG){ + + /** + * 上报闪退日志 + */ + public static void uploadErrorLog(Context context) { + if (!CommonAppConfig.IS_UPLOAD_ERROR_LOG) { return; } - File file = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()+File.separator+"error.log"); - if(file.exists()){ + File file = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + "error.log"); + if (file.exists()) { Log.i("异常上传", "pushError: 准备上传文件"); String err = FileUtil.loadStringToFile(file); + String time = matcher(".(?<=time\\=).*(?=\\nUserData\\=)", err); + if(time!=null){ + time=time.replace("=",""); + }else{ + time=System.currentTimeMillis()+""; + } PostRequest request = OkGo.post("https://newht.yaoulive.com/index.php/api/error_log/report") .params("log", err) .params("uid", CommonAppConfig.getInstance().getUid()) - .params("time", new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.CHINA).format(new Date())) - .params("isGoogle",CommonAppConfig.IS_GOOGLE_PLAY) - .params("appVersion",CommonAppConfig.getInstance().getVersion()) + .params("time",time) + .params("isGoogle", CommonAppConfig.IS_GOOGLE_PLAY) + .params("appVersion", CommonAppConfig.getInstance().getVersion()) .tag("errorLog") .converter(new StringCallback() { String TAG = "异常上传"; @@ -101,4 +110,13 @@ public class LogUtil { task.start(); } } + + private static String matcher(String regex, String input) { + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(input); + if (matcher.find()) { + return matcher.group(); + } + return null; + } } diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index e8ae1fcbb..a3fcc4fae 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -471,7 +471,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //获取指导员账号 ConversationIMListManager.get(this).getUserInstructor(this); checkVersion(); - } @Override