new Thread(new Runnable() {
@Override
public void run() {
File logFile = new File("/sdcard/logcat.txt");
if(logFile.exists())
logFile.delete();
try {
Process process = Runtime.getRuntime().exec("logcat -c");
// process = Runtime.getRuntime().exec("logcat -f " + logFile + " *:S MainActivity:D MyActivity2:D");
process = Runtime.getRuntime().exec("logcat -f " + logFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
From:http://www.journal.deviantdev.com/android-log-logcat-to-file-while-runtime/
logcat -f /sdcard/log.log -v time -s tag