-1

I'm currently developing an android app. I noticed a very rare error which Leeds to a crash of my app. Unfortunately, I had my smartphone never connected to my PC when it occurred. So, is there a way to automatically save all logs to server/ database (and especially the thrown run time exceptions). The error data should be overwritten on every start of my app, so that it contains only the logs of the last run... How can I achieve that?

Thanks Mahak Singhvi

Singhvi Ji
  • 15
  • 4
  • Here is a post that talks about your question: https://stackoverflow.com/questions/1756296/android-writing-logs-to-text-file – acarlstein Aug 09 '18 at 13:25

1 Answers1

0

Logcat

You can use Logcat. It is a command-line tool that dumps a log of system messages, stack traces and messages that you have written from your app with the Log class.

You can run logcat as an adb command (or directly in a shell prompt).

adb logcat

Logcat can also write directly to a file:

public static void backupLogcatToFile(Context context) {    
  String fileName = "logcat_" + System.currentTimeMillis() + ".txt";
  File outputFile = new File(context.getExternalCacheDir(), fileName);
  Process process = Runtime.getRuntime().exec("logcat -f " + outputFile.getAbsolutePath());
}

OpenSource projects

The project CatSaver is an Android service that automatically saves logcat. It provides an HTTP server that allows you to save and download logcat data without adb-connecting to the device.

If you need to collect crash log after the app is released, you can use ACRA.

Trevor65
  • 328
  • 1
  • 8