NitZRobotKoder
NitZRobotKoder

Reputation: 1096

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?

Upvotes: 3

Views: 12570

Answers (6)

NitZRobotKoder
NitZRobotKoder

Reputation: 1096

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();
    } 
}

Upvotes: 5

Hitendra
Hitendra

Reputation: 3226

You can use acra with your application.It helps you to get the crash reports in your gdoc account you can also configure it to get an email for crash report.Once your app goes live then it also helps you to get the crash report. http://code.google.com/p/acra/

Upvotes: 0

Vivek Khandelwal
Vivek Khandelwal

Reputation: 7849

The Android Log will be save only when Your application has Debugging = true in manifest (i.e when you are in Debug mode).

See Documentation at Turn off logging and debugging

So in that case if you want the log then you can implement Thread.setDefaultUncaughtExceptionHandler (Thread.UncaughtExceptionHandler handler)

This will be called always when your application is force closed due to Exception.

What you do is save the StackTrace in a file in append mode.

You can also use this in Debug Mode.

LogCat is a Queue so there are changes that you will miss your log (old Log will be automatically discarded).

I suggest you to implement setDefaultUncaughtExceptionHandler so you never miss any exception log. Also take care to delete the file after use or else your file will became very big in size by time.

Upvotes: 2

nuala
nuala

Reputation: 2689

You should use unique Logtags for your messages so you can Filter the cat for that. E.g. getPackageName() is a nice candidate and it's returning a string.

In Eclipse you can click on the green + to add another filer for LogCats View. In the window you repeat your tag in the field "by log tag".

Also it seems there's automatically a new Tab called "session filter" when I start my app from Eclipse - providing relevant Logs including but not only the ones written by the programmer.

You can also grab the log directly from the console using Android Developer Bridge. adb logcat is the command you're looking for and according to man there are also the same filter settings applicable. Though I couldn't figure out the syntax :)

Upvotes: 0

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39718

Assuming you have access to the device:

  1. Hook the device up to the computer.
  2. Run DDMS, select the device, and go to the file explorer tab.
  3. Find the file referenced in LogCat, and click on the Pull from Device button near the top.

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75636

install aLogCat app, then if your app crashes, launch it. Use filter (from menu) to narrow data to related to your application and eventually save it or send from device via mail to you. But it won't do much magic - if logs are phisically gone from device it won't send you more you can have with DDMS. It's however quite useful if your users report crashes.

Upvotes: 0

Related Questions