Skip to content

Instantly share code, notes, and snippets.

@OSemenovBoyarka
Created June 27, 2014 07:09
Show Gist options
  • Save OSemenovBoyarka/18b3250329e37a3dfd38 to your computer and use it in GitHub Desktop.
Save OSemenovBoyarka/18b3250329e37a3dfd38 to your computer and use it in GitHub Desktop.
Method starts logcat to save logs to sdcard in android. Remember to kill log process when it not needed anymore
public void createLog() {
File logFile = new File(Environment.getExternalStorageDirectory() + File.separator + "FILE_NAME.log");
if (!logFile.exists()) {
try {
logFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
int sizePerFile = 6000; // size in kilobytes
int rotationCount = 10; // file rotation count
String filter = "D"; // Debug priority
String[] args = new String[]{"logcat",
"-v", "time",
"-f", logFile.getAbsolutePath(),
"-r", Integer.toString(sizePerFile),
"-n", Integer.toString(rotationCount),
"*:" + filter};
try {
Process logProcess = Runtime.getRuntime().exec(args);
} catch (IOException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment