I'm trying to redirect the log of my app to the sdcard file. But i failed to do so. I'm trying something like this.
String cmd= "logcat -v time ActivityManager:W myapp:D *:* >\""+file.getAbsolutePath()+"\"";
Runtime.getRuntime().exec(cmd);
I tried the -f option also but it is not working either.
They are stored as circular memory buffers on the device. If you run "adb logcat > myfile" on your host system, you can retrieve the content into a file.
Android 4.0 and older You can either download the SDK and use adb logcat or get Logcat Extrem from the Google Play Store, which shows the log directly on your phone. Alternatively, you can use Terminal Emulator with command "logcat > /sdcard/log. txt" for continuous writing of the log to a file on the SD Card.
The Log class allows you to create log messages that appear in logcat.
This is my worked version:
try {
File filename = new File(Environment.getExternalStorageDirectory()+"/logfile.log");
filename.createNewFile();
String cmd = "logcat -d -f "+filename.getAbsolutePath();
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
find your logfile /sdcard/logfile.log
use logcat -f <filename>
in order to dump it to a file in the filesystem.
Make sure the filename you're using is in the sdcard, i.e. starts with /sdcard/...
.
Also, in order to pass arguments to the logcat
program, you should pass the exec
method an array of strings (and not one string):
String[] cmd = new String[] { "logcat", "-f", "/sdcard/myfilename", "-v", "time", "ActivityManager:W", "myapp:D" };
Finally, if all else fails, use the full path for logcat: /system/bin/logcat
instead of just logcat
.
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