4

I need to write entire Logcat in to sdcard not the filtered Logcat. So I tried doing this way

String[] cmd  ={"/system/bin/logcat " +"-f"+" /sdcard/d.txt"};
    Log.d("NTK","cmd string"+cmd);
    Runtime run = Runtime.getRuntime();

    Process pr;
    try {
        pr = run.exec(cmd);

    pr.waitFor();
    BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String line = "";
    while ((line=buf.readLine())!=null) {
        System.out.println(line);
        Log.i(NTL, "lines"+line);
    }
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I have given all permissions in manifest file too.

Not able to write logcat in to sdcard.

RanjitRock
  • 1,421
  • 5
  • 20
  • 36
  • Please find the similar Question for this :[LogCat on SDCard][1] [1]: http://stackoverflow.com/questions/6970169/stream-android-logcat-output-to-an-sd-card – NovusMobile Jan 24 '12 at 05:17
  • what is the problem you are facing? – Lalit Poptani Jan 24 '12 at 05:17
  • 2
    i have solved the issue buy executing "/system/bin/logcat -b main -f /sdcard/logcat.txt" .Here '-b main ' allows you to select alternate logcat buffers i.e(main,radio,events).-f pipelines the logcat buffer to sdcard. – RanjitRock Jan 24 '12 at 10:30

1 Answers1

2

You can have this Tutorial for Reading the Logs. And for writing the logs in the file you can simply use FileWriter give path of the file with file name.

try {
            File root = Environment.getExternalStorageDirectory();
            if (root.canWrite()) {
                File gpslogfile = new File(root, "log.txt");
                FileWriter gpswriter = new FileWriter(gpslogfile, true);
                BufferedWriter out = new BufferedWriter(gpswriter);
                out.append(DataToWrite);
                out.close();
            }
        } catch (IOException e) {
            Log.d("Log: ", "Could not write file " + e.getMessage());
        }
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242