Amit_android Amit_android - 3 months ago 20
Android Question

Catch LogCat programmatically or export it to file?

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


Working fine for me but not for mytag .

I am also using the code:

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";


But it returns empty file.

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

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