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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With