新增全量日志采集系统

This commit is contained in:
zlzw 2022-11-11 17:47:28 +08:00
parent 042f53e134
commit 834170e272
4 changed files with 164 additions and 91 deletions

View File

@ -1,14 +1,19 @@
package com.shayu.phonelive.utils; package com.shayu.phonelive.utils;
import static java.text.DateFormat.DEFAULT;
import android.content.Context; import android.content.Context;
import com.yunbao.common.utils.FileUtil; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.utils.ToastUtil;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URLEncoder; import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class LogUtils { public class LogUtils {
public static void start(Context context) { public static void start(Context context) {
@ -31,18 +36,26 @@ public class LogUtils {
}; };
Process process = Runtime.getRuntime().exec(exec); Process process = Runtime.getRuntime().exec(exec);
StringBuilder builder = new StringBuilder(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024);
String line; String line;
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()); PrintWriter writer = null;
String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator);
if (dir.listFiles() != null) {
for (File file : dir.listFiles()) {
if (!file.getName().endsWith(today+".log") && !file.getName().endsWith("error.log")) {
file.delete();
}
}
}
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
FileOutputStream os = new FileOutputStream(saveFile);
writer = new PrintWriter(os);
while ((line = bufferedReader.readLine()) != null) { while ((line = bufferedReader.readLine()) != null) {
builder.append(line).append("\n"); writer.append(line).write("\n");
if (builder.length() > 65500) {
FileUtil.saveAddStringToFile(saveFile, builder.toString(), "logcat.log");
builder.setLength(0);
} }
} writer.flush();
writer.close();
exec = new String[]{ exec = new String[]{
"logcat", "logcat",
"-c" "-c"
@ -52,10 +65,10 @@ public class LogUtils {
start(context); start(context);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
ToastUtil.show("");
} }
} }
}).start(); }).start();
} }
} }

View File

@ -1,9 +1,22 @@
package com.yunbao.common.utils; package com.yunbao.common.utils;
import static androidx.core.content.PermissionChecker.PERMISSION_GRANTED;
import static java.text.DateFormat.DEFAULT;
import android.Manifest;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;
import androidx.core.content.PermissionChecker;
import com.lzy.okgo.OkGo; import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback; import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Progress; import com.lzy.okgo.model.Progress;
@ -16,6 +29,9 @@ import com.yunbao.common.CommonAppConfig;
import java.io.File; import java.io.File;
import java.io.FileWriter; 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.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -119,4 +135,30 @@ public class LogUtil {
} }
return null; return null;
} }
public static void shareFile(Context context) {
if(PermissionChecker.checkCallingOrSelfPermission(context,"android.permission.WRITE_EXTERNAL_STORAGE")!= PERMISSION_GRANTED){
ActivityCompat.requestPermissions((Activity) context,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},100);
return;
}
String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
File file = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
file.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+file.getName()));
if (file.exists()) {
Intent share = new Intent(Intent.ACTION_SEND);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
share.putExtra(Intent.EXTRA_STREAM, contentUri);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
}
share.setType("application/vnd.ms-excel");
share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(share, "分享文件"));
}
}
} }

View File

@ -1062,7 +1062,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
return bitmap; return bitmap;
} }
private String TAG="多人PK";
private String TAG = "多人PK";
/** /**
* 退出多人PK * 退出多人PK
*/ */
@ -1186,12 +1188,19 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
@Override @Override
public void onSuccess(int code, String msgs, String[] info) { public void onSuccess(int code, String msgs, String[] info) {
if (code == 0) { if (code == 0) {
Log.i("多人PK","1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info)+" mApplyUid = "+mApplyUid); Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid);
if (info.length == 0) { HttpClient.getInstance().get("live.getdrnum", "live.getdrnum")
.execute(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
boolean agree=true;
if (code != 0) {
ToastUtil.show("多人PK次数已用完"); ToastUtil.show("多人PK次数已用完");
return; agree=false;
} }
rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, true, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() { rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, agree, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom") HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom")
@ -1232,7 +1241,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
Log.e("ry", "发送失敗"); Log.e("ry", "发送失敗");
} }
}); });
if(info.length==0){
return;
}
JSONObject obj = JSONObject.parseObject(info[0]); JSONObject obj = JSONObject.parseObject(info[0]);
JSONArray users = obj.getJSONArray("userlist"); JSONArray users = obj.getJSONArray("userlist");
@ -1281,6 +1292,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
ToastUtil.show("接受失败"); ToastUtil.show("接受失败");
} }
}); });
}
});
} }
} }

View File

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.LogUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.main.BuildConfig; import com.yunbao.main.BuildConfig;
import com.yunbao.main.R; import com.yunbao.main.R;
@ -50,6 +51,9 @@ public class SettingAdapter extends RecyclerView.Adapter {
if (tag != null) { if (tag != null) {
int position = (int) tag; int position = (int) tag;
SettingBean bean = mList.get(position); SettingBean bean = mList.get(position);
if(bean.getId()==19){
LogUtil.shareFile(context);
}
if (mOnItemClickListener != null) { if (mOnItemClickListener != null) {
mOnItemClickListener.onItemClick(bean, position); mOnItemClickListener.onItemClick(bean, position);
} }