How to display long messages in logcat

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

    if print json string, can use code below

        @JvmStatic
        fun j(level: Int, tag: String? = null, msg: String) {
            if (debug) {
                if (TextUtils.isEmpty(msg)) {
                    p(level, tag, msg)
                } else {
                    val message: String
                    message = try {
                        when {
                            msg.startsWith("{") -> {
                                val jsonObject = JSONObject(msg)
                                jsonObject.toString(4)
                            }
                            msg.startsWith("[") -> {
                                val jsonArray = JSONArray(msg)
                                jsonArray.toString(4)
                            }
                            else -> msg
                        }
                    } catch (e: JSONException) {
                        e.printStackTrace()
                        msg
                    }
                    p(level, tag, "╔═══════════════════════════════════════════════════════════════════════════════════════", false)
                    val lines = message.split(LINE_SEPARATOR.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
                    for (line in lines) {
                        p(level, tag, "║ $line", false)
                    }
                    p(level, tag, "╚═══════════════════════════════════════════════════════════════════════════════════════", false)
                }
            }
        }
    

    full code

    CXLogUtil.j("json-tag","{}")

提交回复
热议问题