Brijesh Masrani Brijesh Masrani - 1 year ago 164
Android Question

Write android logcat data to a file

I want to dump Android logcat in a file whenever user wants to collect logs. Through adb tools we can redirect logs to a file using

adb logcat -f filename
, but how can I do this programmatically?

Answer Source

Here is an example of reading the logs.

You could change this to write to a file instead of to a TextView.

Need permission in AndroidManifest:

<uses-permission android:name="android.permission.READ_LOGS" />


public class LogTest extends Activity {
  public void onCreate(Bundle savedInstanceState) {
    try {
      Process process = Runtime.getRuntime().exec("logcat -d");
      BufferedReader bufferedReader = new BufferedReader(
      new InputStreamReader(process.getInputStream()));

      StringBuilder log = new StringBuilder();
      String line;
      while ((line = bufferedReader.readLine()) != null) {
      TextView tv = (TextView) findViewById(;
    } catch (IOException e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download