Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to access automatically any Log in Logcat by a double click?

Is there any way to access automatically any Log in Logcat by a double click ?

Actually, when there is an error crashing my Android Application, I can double click on the line saying for instance

at com.myapp.mypackage$Class.function(File.java:117)

And by Double-clicking on this line, I am automatically redirected to the related line of my code.

But, when I try to generate the same line in another Log, example :

Log.e("TAG", "at com.myapp.mypackage$Class.function(File.java:117)");

The Double-Click doesn't work anymore ...

Any ideas ?

like image 361
Thordax Avatar asked Nov 09 '11 15:11

Thordax


2 Answers

If you want to create a log in logcat that can be clicked and go to your line use the following method to create it:

Enjoy!

public static void showLogCat(String tag, String msg) {

        StackTraceElement[] stackTraceElement = Thread.currentThread()
                .getStackTrace();
        int currentIndex = -1;
        for (int i = 0; i < stackTraceElement.length; i++) {
            if (stackTraceElement[i].getMethodName().compareTo("showLogCat") == 0)
            {
                currentIndex = i + 1;
                break;
            }
        }

        String fullClassName = stackTraceElement[currentIndex].getClassName();
        String className = fullClassName.substring(fullClassName
                .lastIndexOf(".") + 1);
        String methodName = stackTraceElement[currentIndex].getMethodName();
        String lineNumber = String
                .valueOf(stackTraceElement[currentIndex].getLineNumber());

        Log.i(tag, msg);
        Log.i(tag + " position", "at " + fullClassName + "." + methodName + "("
                + className + ".java:" + lineNumber + ")");

    }
like image 163
Bobs Avatar answered Oct 13 '22 00:10

Bobs


If you don't mind the clutter in your log, you can easily just add a new Exception() to the log message

Log.e("TAG", "Looky here see", new Exception());
like image 22
Patrick Avatar answered Oct 12 '22 23:10

Patrick