0

Currently working on an application which runs in background. Implemented a solution which will get crash logs, but for system error messages it doesn't works. So, Looking for solution which will also records all the application error logs.

What i have implemented :

// Setup handler for uncaught exceptions in onCreate of Application Class.
        Thread.setDefaultUncaughtExceptionHandler { thread, e ->
            handleUncaughtException(e)
        }


private fun handleUncaughtException(e: Throwable) {
var arr = e.stackTrace
        var report = """
            $e
            
            
            """.trimIndent()
        report += "--------- Stack trace ---------\n\n"
        for (element in arr) {
            report += """    $element
"""
        }
        report += "-------------------------------\n\n"

        // If the exception was thrown in a background thread inside
        // AsyncTask, then the actual exception can be found with getCause

        report += "--------- Cause ---------\n\n"
        val cause: Throwable? = e.cause
        if (cause != null) {
            report += """
                $cause
                
                
                """.trimIndent()
            arr = cause.stackTrace
            for (element in arr) {
                report += """    $element    """
            }
        }
        report += "-------------------------------\n\n"
}
NarenderNishad
  • 1,028
  • 1
  • 17
  • 29

0 Answers0