Created
June 27, 2014 07:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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