大佬教程收集整理的这篇文章主要介绍了如何只将应用程序日志写入android中的外部文件,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public String writeLogToFile() { try { Process process = Runtime.getRuntime().exec("logcat -d"); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.geTinputStream())); StringBuilder log=new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { log.append(linE); } bufferedReader.close(); return log.toString(); } catch (IOException E) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
它还打印系统级别的所有日志.是的我放-d所以它是打印但如果我把-e或-i它不写文件.我只想写Log.e(“Offset”,“”mOffset).我哪里做错了?
在logcat的参数中,我指定读取最后200行并随时间显示日志.
public String writeLogToFile() { StringBuilder logs = new StringBuilder(); int pid = android.os.process.myPid(); String pidPattern = String.format("%d):",pid); try { Process process = new ProcessBuilder() .command("logcat","-t","200","-v","time") .redirectErrorStream(true) .start(); InputStream in = null; try { in = process.geTinputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { if (line.contains(pidPattern)) { logs.append(linE).append("\n"); } } } finally { if (in != null) { try { in.close(); } catch (IOException E) { Log.e(tag,"CAnnot close input stream",E); } } } } catch (IOException E) { Log.e(tag,"CAnnot read logs",E); } return log.toString(); }
以上是大佬教程为你收集整理的如何只将应用程序日志写入android中的外部文件全部内容,希望文章能够帮你解决如何只将应用程序日志写入android中的外部文件所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。