Android's Logcat message has a character-length limit that will be truncated directly

Source: Internet
Author: User

When I want to output enough debugging information in Logcat today, we find that the information returned from Logcat is obviously less in the following section.

Feel a bit strange, thought is the code problem, looked for a bit, found not;

So guge. The original logcat on the implementation of the memory allocation for the message is about 4k. So the content is discarded directly;

Not output;

Also found that logcat for "\ n" line break automatically as a symbol is automatically separated into multiple log output, but you log.d (null, "There are multiple \ n more than 4k length characters");

This kind of information, although how many will produce the number of log, but you pass to this message the most accept is about 4k, the back not, and then in accordance with the principle of "cut";


So, think about it, write a debug class yourself to slice more than 4k of the message to use multiple LOG.D output;

The simple implementation is as follows:

Package Com.qidizi.softkeyboard;import Android.util.log;class Debug {//Use log to display debug information because log has a 4k character length limit per message on implementation// So here you use your own section to output a messagepublic static void show (String str) {str = Str.trim (); int index = 0;int maxLength = 4000; String Sub;while (Index < Str.length ()) {//Java characters are not allowed to specify more than the total length of endif (Str.length () <= index + maxLength) {sub = Str.s Ubstring (index);} else {sub = str.substring (index, maxLength);} Index + = maxLength; LOG.I ("Qidizi_debug", Sub.trim ());}}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android's Logcat message has a character-length limit that will be truncated directly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.