jason
jason

Reputation: 7164

How to print very large string using Logcat

I'm printing a large string using this method :

   private static final int LOGCAT_MAX_LENGTH = 3950;

    private void logLongJsonStringIfDebuggable(String s) {
        if (BuildConfig.DEBUG) {
            while (s.length() > LOGCAT_MAX_LENGTH) {
                int substringIndex = s.lastIndexOf(",", LOGCAT_MAX_LENGTH);
                if (substringIndex == -1)
                    substringIndex = LOGCAT_MAX_LENGTH;
                Log.d("TAG", s.substring(0, substringIndex));
                s = s.substring(substringIndex).trim();
            }
            Log.d("TAG", s);
        }
    }

This works fine, but Logcat prints too many strings that I can not see all of the content of the string in my Logcat. I can see only most recent ones. Can you tell me how I can view all Logcat logs in Logcat? Or can you show me a way to print all logs to a file or something like that? Thanks.

Upvotes: 1

Views: 2609

Answers (1)

Pankaj Kumar
Pankaj Kumar

Reputation: 82938

Write your log on file, so your log-reset problem will not be there and you can see full log.

Use below command on terminal

adb logcat > path_of_file/LogFile.log // Extension can be .txt also

Upvotes: 3

Related Questions