我如何在日志中输出都在Android上没有截断? [英] How do I output everything in the log on Android without truncation?
本文介绍了我如何在日志中输出都在Android上没有截断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要输出大量的数据,以我的日志在Android ...但它截断数据。
I would like to output a lot of data to my log on Android...but it's truncating the data.
如何从截断我的日志我做prevent呢?
How do I prevent it from truncating my logs?
推荐答案
logcat的截断后,4000个字符的数据,所以你可以以块的形式写出来:
Logcat truncates data after 4000 characters so you could write it out in chunks:
public static final int LOGCAT_MAX_LINE_LIMIT = 4000;
public static final String TAG = "log_tag";
private void showLog(String message) {
if (message.length() > LOGCAT_MAX_LINE_LIMIT) {
int chunkCount = message.length() / LOGCAT_MAX_LINE_LIMIT;
for (int i = 0; i <= chunkCount; i++) {
int max = LOGCAT_MAX_LINE_LIMIT * (i + 1);
if (max >= message.length()) {
Log.d(TAG, message.substring(LOGCAT_MAX_LINE_LIMIT * i));
} else {
Log.d(TAG, message.substring(LOGCAT_MAX_LINE_LIMIT * i, max));
}
}
} else {
Log.d(TAG, message);
}
}
这篇关于我如何在日志中输出都在Android上没有截断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文