How to display long messages in logcat

后端 未结 10 1046
轻奢々
轻奢々 2020-11-29 01:08

I am trying to display long message on logcat. If the length of message is more than 1000 characters, it gets broken.

What is the mechanism to show all characters o

10条回答
  •  既然无缘
    2020-11-29 01:25

    As a follow on to spatulamania answer I wrote a wrapper class which handles this for you. You just need to change the import and it will log everything

    public class Log {
    
        public static void d(String TAG, String message) {
            int maxLogSize = 2000;
            for(int i = 0; i <= message.length() / maxLogSize; i++) {
                int start = i * maxLogSize;
                int end = (i+1) * maxLogSize;
                end = end > message.length() ? message.length() : end;
                android.util.Log.d(TAG, message.substring(start, end));
            }
        }
    
    }
    

提交回复
热议问题