How to display long messages in logcat

后端 未结 10 1063
轻奢々
轻奢々 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:29

    Here is a Kotlin version for the @spatulamania answer (especially for lazy/smart peooples):

    val maxLogSize = 1000
    val stringLength = yourString.length
    for (i in 0..stringLength / maxLogSize) {
        val start = i * maxLogSize
        var end = (i + 1) * maxLogSize
        end = if (end > yourString.length) yourString.length else end
        Log.v("YOURTAG", yourString.substring(start, end))
    }
    

提交回复
热议问题