Search code examples
androidadblogcatlogging

Capture Complete LOGS In Android


I was wondering how do i take complete logs from android device (From the point of My application initialize to any crash or till force close of my application).

Reason i am posting here is my application is crashed some point,but when i take logs using DDMS/Logcat my crash details are over written with new logs.


How do i get my crashed reason logs..


Specially looking to capture Native Code Crash.

i.e I/DEBUG (21835): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000004...


Will this adb logcat > crash.txt ensures me that write to file will happen forever?


Solution

  • I tried this Works Real Well,Not sure How much battery it will consume..If your Application is in Testing Stage You can use this..Before Release you got to Remove this code and Publish..

    private void writeADBLogs(){
         BufferedWriter bufferedWriter = null;
    
          try {
             final File file = new File(sdcardPath);
            bufferedWriter = new BufferedWriter(new FileWriter(file,true));
            Process process = Runtime.getRuntime().exec("logcat -d");
            BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream()));
    
            String oneLine;
              while ((oneLine= bufferedReader.readLine()) != null) {
                  bufferedWriter.write(oneLine);
                  bufferedWriter.newLine();
              }
        } catch (IOException e) {
            e.printStackTrace();
        } 
    }