0

I am writing my own logger that stores all the entries into a SQLite database using Sugar ORM. I can do normal log.e, log.d, log.i just fine, but in the event the app crashes I want my logger to be able to get the exception message and store it into the SQLite.

How would I get the exception message so I can store it into my SQLite database before the app crashes?

Thanks!

Alan
  • 9,091
  • 12
  • 51
  • 92
  • Would the solution to http://stackoverflow.com/questions/12346866/send-a-broadcast-from-logcat solve your problem? – SilverCorvus Mar 04 '15 at 15:40
  • "in the event the app crashes I want my logger to be able to..." --> why isn't your priority to prevent app crashes instead of saving logs ? – 2Dee Mar 04 '15 at 15:41
  • @2dee obviously I want to prevent crashing, but I want my custom logger to be able to log crashes just like how regular loggers are able to do. I would think even if you try to make your app as bullet proof as possible, full featured logging should be implemented regardless. – Alan Mar 04 '15 at 15:49

1 Answers1

1

Use try-catch and all other exceptions you can log like this example shows:

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            _logger.logUncaughtException(e);
        }

    });
dieter
  • 8,413
  • 5
  • 43
  • 69
  • can this be added to a logging library? So when you are setting the uncaughtexception, it would call the listener in a library? – Alan Mar 04 '15 at 16:28
  • @Alan it is static call, so you can do it everywhere. – dieter Mar 04 '15 at 18:30