如何在 logcat 中显示长消息 [英] How to display long messages in logcat

查看:33
本文介绍了如何在 logcat 中显示长消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 logcat 上显示长消息.如果消息的长度超过 1000 个字符,它就会被破坏.

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

logcat 显示长消息所有字符的机制是什么?

What is the mechanism to show all characters of long message in logcat?

推荐答案

如果 logcat 的长度上限为 1000,那么您可以使用 String.subString() 拆分要记录的字符串并将其分块记录.例如:

If logcat is capping the length at 1000 then you can split the string you want to log with String.subString() and log it in pieces. For example:

int maxLogSize = 1000;
for(int i = 0; i <= veryLongString.length() / maxLogSize; i++) {
    int start = i * maxLogSize;
    int end = (i+1) * maxLogSize;
    end = end > veryLongString.length() ? veryLongString.length() : end;
    Log.v(TAG, veryLongString.substring(start, end));
}

这篇关于如何在 logcat 中显示长消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆