以编程方式捕获LogCat还是将其导出到文件? [英] Catch LogCat programmatically or export it to file?

查看:57
本文介绍了以编程方式捕获LogCat还是将其导出到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想过滤一个logcat

I want to filter a logcat

String myCommand="logcat -f /sdcard/output.txt"; //no filters, keep writing  
myCommand="logcat -d -f /sdcard/output.txt"; //no filters, just a dump

对我来说工作正常,但对mytag却不行.

Working fine for me but not for mytag .

我也在使用代码:

String myCommand="logcat myTag *:S"; //the equivalent of logcat -s myTag  
myCommand="logcat -s myTag:D";   
myCommand="logcat -s myTag:E myTag2:D";  
myCommand="logcat myTag:E myTag2:D";  

但是它返回空文件.

推荐答案

File filename = new File(Environment.getExternalStorageDirectory()+"/mylog.log"); 
filename.createNewFile(); 
String cmd = "logcat -d -f"+filename.getAbsolutePath();
Runtime.getRuntime().exec(cmd);

对我有用.但是对于所有logcat输出,不是针对特殊标签(mytag).

it works for me. but for all logcat output not for special tag(mytag).

这篇关于以编程方式捕获LogCat还是将其导出到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆