根据后端需求修改上报日志接口参数

This commit is contained in:
18401019693 2022-10-21 18:28:50 +08:00 committed by zlzw
parent 38a269ae1c
commit 90e249e2d7
4 changed files with 34 additions and 14 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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<String> request = OkGo.<String>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;
}
}

View File

@ -471,7 +471,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
//获取指导员账号
ConversationIMListManager.get(this).getUserInstructor(this);
checkVersion();
}
@Override