protected static JSONObject appendStackMetadata(JSONObject additionalMetadata) {
        JSONObject jsonMetadata;

        if(additionalMetadata != null){
            jsonMetadata = additionalMetadata;
        }
        else{
            jsonMetadata = new JSONObject();
        }

        try {
            // try/catch Exception wraps all because I don't know yet if I can trust getStackTrace... needs more testing
            // below is slightly more performant than: Thread.currentThread().getStackTrace();
            StackTraceElement[] stackTraceElements = new Exception().getStackTrace();

            int index = 0;
            // find the start of the Logger call stack:
            while(!stackTraceElements[index].getClassName ().equals (LogPersister.class.getName())) {
                index++;
            }
            // then find the caller:
            while(stackTraceElements[index].getClassName().equals (LogPersister.class.getName())
                    || stackTraceElements[index].getClassName().startsWith (JULHandler.class.getName())
                    || stackTraceElements[index].getClassName().startsWith (java.util.logging.Logger.class.getName())
                    || stackTraceElements[index].getClassName().startsWith (BMSAnalytics.class.getName())) {
                index++;
            }

            jsonMetadata.put ("$class", stackTraceElements[index].getClassName ());
            jsonMetadata.put ("$file", stackTraceElements[index].getFileName ());
            jsonMetadata.put ("$method", stackTraceElements[index].getMethodName ());
            jsonMetadata.put ("$line", stackTraceElements[index].getLineNumber ());
            jsonMetadata.put ("$src", "java");

        } catch (Exception e) {
            Log.e(LOG_TAG_NAME, "Could not generate jsonMetadata object.", e);
        }

        return jsonMetadata;
    }
protected static JSONObject appendStackMetadata(JSONObject additionalMetadata) {
        JSONObject jsonMetadata;

        if(additionalMetadata != null){
            jsonMetadata = additionalMetadata;
        }
        else{
            jsonMetadata = new JSONObject();
        }

        try {
            
            
            StackTraceElement[] stackTraceElements = new Exception().getStackTrace();

            int index = 0;
            
            while(!stackTraceElements[index].getClassName ().equals (LogPersister.class.getName())) {
                index++;
            }
            
            while(stackTraceElements[index].getClassName().equals (LogPersister.class.getName())
                    || stackTraceElements[index].getClassName().startsWith (JULHandler.class.getName())
                    || stackTraceElements[index].getClassName().startsWith (java.util.logging.Logger.class.getName())
                    || stackTraceElements[index].getClassName().startsWith (BMSAnalytics.class.getName())) {
                index++;
            }

            jsonMetadata.put ("$class", stackTraceElements[index].getClassName ());
            jsonMetadata.put ("$file", stackTraceElements[index].getFileName ());
            jsonMetadata.put ("$method", stackTraceElements[index].getMethodName ());
            jsonMetadata.put ("$line", stackTraceElements[index].getLineNumber ());
            jsonMetadata.put ("$src", "java");

        } catch (Exception e) {
            Log.e(LOG_TAG_NAME, "Could not generate jsonMetadata object.", e);
        }

        return jsonMetadata;
    }
protected static JSONObject appendStackMetadata ( JSONObject additionalMetadata ) { JSONObject jsonMetadata ; if ( additionalMetadata != null ) { jsonMetadata = additionalMetadata ; } else { jsonMetadata = new JSONObject ( ) ; } try { // try/catch Exception wraps all because I don't know yet if I can trust getStackTrace... needs more testing // below is slightly more performant than: Thread.currentThread().getStackTrace(); StackTraceElement [ ] stackTraceElements = new Exception ( ) . getStackTrace ( ) ; int index = 0 ; // find the start of the Logger call stack: while ( ! stackTraceElements [ index ] . getClassName ( ) . equals ( LogPersister . class . getName ( ) ) ) { index ++ ; } // then find the caller: while ( stackTraceElements [ index ] . getClassName ( ) . equals ( LogPersister . class . getName ( ) ) || stackTraceElements [ index ] . getClassName ( ) . startsWith ( JULHandler . class . getName ( ) ) || stackTraceElements [ index ] . getClassName ( ) . startsWith ( java . util . logging . Logger . class . getName ( ) ) || stackTraceElements [ index ] . getClassName ( ) . startsWith ( BMSAnalytics . class . getName ( ) ) ) { index ++ ; } jsonMetadata . put ( "$class" , stackTraceElements [ index ] . getClassName ( ) ) ; jsonMetadata . put ( "$file" , stackTraceElements [ index ] . getFileName ( ) ) ; jsonMetadata . put ( "$method" , stackTraceElements [ index ] . getMethodName ( ) ) ; jsonMetadata . put ( "$line" , stackTraceElements [ index ] . getLineNumber ( ) ) ; jsonMetadata . put ( "$src" , "java" ) ; } catch ( Exception e ) { Log . e ( LOG_TAG_NAME , "Could not generate jsonMetadata object." , e ) ; } return jsonMetadata ; }
Get stack trace caused by Logger exceptions

@return Returns the JSONObject with stack metadata
Get stack trace caused by Logger exceptions