logging - How to get the error log from android process and when to call the get error log method? -


i have implemented try catch on exception possible places. there different other exception thrown android os[database exception, permission , other exception]. want write error log data file{only there crash on our application}.

already have code write given data file. want know how error log android process.

if there crash app instance not available. , don't know exact place call error log method. on this. please me on this.

in application class can initialize unhandle exception. callbask method have trowhable object. object can crash log data , same data written file.

application class:

public class myapplication extends application {     // uncaught exception handler variable     private uncaughtexceptionhandler defaultueh;      public myapplication() {         defaultueh = thread.getdefaultuncaughtexceptionhandler();          // setup handler uncaught exception         thread.setdefaultuncaughtexceptionhandler(_uncaughtexceptionhandler);     }      // handler listener     private thread.uncaughtexceptionhandler _uncaughtexceptionhandler = new thread.uncaughtexceptionhandler() {         @override         public void uncaughtexception(thread thread, throwable ex) {                         //to write crash log data file             apputil.getinstance().writeactivitylogtofile(true,                     geterrormessgae(ex));              // re-throw critical exception further os (important) handle             defaultueh.uncaughtexception(thread, ex);             // system.exit(2);         }     };      /**      * crash log message throwable object      *       * @param e      *            - throwable exception object      * @return - crash log      */     private string geterrormessgae(throwable e) {         stacktraceelement[] stacktrackelementarray = e.getstacktrace();         string crashlog = e.tostring() + "\n\n";         crashlog += "--------- stack trace ---------\n\n";         (int = 0; < stacktrackelementarray.length; i++) {             crashlog += "    " + stacktrackelementarray[i].tostring() + "\n";         }         crashlog += "-------------------------------\n\n";          // if exception thrown in background thread inside         // asynctask, actual exception can found getcause         crashlog += "--------- cause ---------\n\n";         throwable cause = e.getcause();         if (cause != null) {             crashlog += cause.tostring() + "\n\n";             stacktrackelementarray = cause.getstacktrace();             (int = 0; < stacktrackelementarray.length; i++) {                 crashlog += "    " + stacktrackelementarray[i].tostring()                         + "\n";             }         }         crashlog += "-------------------------------\n\n";         return crashlog;     } } 

declare application class in manifest in following tag:


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -