Launch Logcat programmatically in Android

less than 1 minute read

Today I wanted to write logcat output to a file while my application is running. To do so I executed the following code:

public void executeLogcat(){
	File logFile = new File("/mnt/sdcard/arxeion.log"); // log file name
	int sizePerFile = 60; // size in kilobytes
	int rotationCount = 10; // file rotation count
	String filter = "D"; // Debug priority

	String[] args = new String[] { "logcat",
					"-v", "time",
					"-r", Integer.toString(sizePerFile),
					"-n", Integer.toString(rotationCount),
					"*:" + filter };

	try {
	} catch (IOException e) {

To execute logcat process we are obliged to add


uses permission in AndroidManifest.xml file.


  1. This code should NOT be used in a release version of your application.
  2. You should control when to kill logcat process, as it will run forever