Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect the content in Logcat to file on android?

Recently, I'm developing a android application. I've got a lot of Log.i or Log.e in my code.

When I test the app on my phone, which is connected to my computer via USB, I can get all the logs under the Logcat. But when my phone not connecting to my computer, I got no idea where the bug comes from because Log.* doesn't write logs to file.

Could anyone give my some suggestions on how to redirect the Log.* to a file with minimal change to my code? Thanks a lot!

p.s.

I've searched about how to redirect Logcat to file using adb logcat. Could anyone tell me how to filter the logs which are corresponding to my current app?

like image 510
Judking Avatar asked Apr 11 '13 02:04

Judking


1 Answers

To save LogCat log to file programmatically on your device use for example this code:

String filePath = Environment.getExternalStorageDirectory() + "/logcat.txt";
Runtime.getRuntime().exec(new String[]{"logcat", "-f", filePath, "MyAppTAG:V", "*:S"});

"MyAppTAG:V" sets the priority level for all tags to Verbose (lowest priority)

"*:S" sets the priority level for all tags to "silent"

If you want to save all logcat just put "*:V".

More information about logcat here.

like image 90
yuralife Avatar answered Nov 07 '22 01:11

yuralife