0

My Android app force close certain time when it is running on device.I want to store that error log in a text file on device.So i can see reason behind force close.Because it is difficult to identify when sudden force close occure when app is running. Can you provide me some way to create a log file on sd card.

Thanks in advance.

I have following code when app start but it after adding this code app is not force close,and log file is showing null.

 Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread thread, Throwable ex) {

            Log.e("UNCAUGHT EXCEPTION", thread.toString());
            Log.e("UNCAUGHT EXCEPTION", ""+ex.getMessage());
            try {
                PrintWriter out = new PrintWriter("mnt/sdcard/log.txt");
                out.println(ex.getMessage());
                out.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
          }
    });
Ravi Bhandari
  • 4,682
  • 8
  • 40
  • 68

3 Answers3

0

You can try to use Thread.setDefaultUncaughtExceptionHandler and save the exception information on the SD card from there.

0

Download ghostlog app from google play store

Add it in lib folder :ghostlog-integration-1.0.3.jar

In mainfest:

<!--Receives intents from Ghost Log app to start & stop the integration service-->
        <receiver android:name="com.readystatesoftware.ghostlog.integration.IntegrationReceiver" 
        android:permission="com.readystatesoftware.ghostlog.permission.READ_LOGS" >
        <intent-filter>
        <action android:name="com.readystatesoftware.ghostlog.integration.COMMAND" />
        </intent-filter>
        </receiver>
        <!--Reads logs and broadcasts them to Ghost Log-->
        <service android:name="com.readystatesoftware.ghostlog.integration.IntegrationService" />

see this link https://github.com/jgilfelt/GhostLog and thanks to Jeff Gilfelt

sunil
  • 660
  • 8
  • 20
0

One way which would be easier to do this:

Download the app CatLog from Google Play https://play.google.com/store/apps/details?id=com.nolanlawson.logcat&hl=en and then replace

e.printStackTrace();

with

Log.e("TAG FOR LOG e.g APP_NAME", Log.getStackTraceString(e));

After that, it will print the stack trace to the Logcat which can be found by doing the following:

Open the Catlog app, search using the search bar for whatever you made the tag in the Log above.

Temena
  • 13
  • 3