Launch Logcat programmatically in Android

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


About cmanios

This entry was posted in Android, Java and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s