新增全量日志采集系统
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
package com.shayu.phonelive.utils;
|
||||
|
||||
import static java.text.DateFormat.DEFAULT;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.yunbao.common.utils.FileUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
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 static void start(Context context) {
|
||||
@@ -31,18 +36,26 @@ public class LogUtils {
|
||||
};
|
||||
|
||||
Process process = Runtime.getRuntime().exec(exec);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024);
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath());
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line).append("\n");
|
||||
if (builder.length() > 65500) {
|
||||
FileUtil.saveAddStringToFile(saveFile, builder.toString(), "logcat.log");
|
||||
builder.setLength(0);
|
||||
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) {
|
||||
writer.append(line).write("\n");
|
||||
}
|
||||
writer.flush();
|
||||
writer.close();
|
||||
exec = new String[]{
|
||||
"logcat",
|
||||
"-c"
|
||||
@@ -52,10 +65,10 @@ public class LogUtils {
|
||||
start(context);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ToastUtil.show("");
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user