Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Set max length of logcat messages

People also ask

What is verbose in Android Logcat?

Verbose: Show all log messages (the default). Debug: Show debug log messages that are useful during development only, as well as the message levels lower in this list. Info: Show expected log messages for regular usage, as well as the message levels lower in this list.

How does Logcat determine buffer size?

First enable Developer options in Settings. Then navigate to the newly visible Developer options entry, scroll down, and click on logger buffer size . This will display options ranging from off to 16Mb . I have found that when switching to off , logcat will still hold and report a buffer size of 64Kb .

How do I stop Logcat from clearing?

Prevent clearing the log when the app crashes By default when the app got crashed the logcat clear's in the android studio. To prevent this, click the right end chooser(Filter Configuration chooser) in the logcat tab then select Edit Filter Configuration option and enter current app name and package name.

How do I freeze Logcat?

Simple solution: In Android monitor, on the right, change No Filters -> Show only selected application. THIS should be THE Answer!


Ok, interesting. I was disappointed to see that the answer was "you can't really expand it". My initial thought was to break it up so I could view the whole thing, so here I share with you how I do just that (not that it's anything fancy nor is it near efficient, but it gets the job done in a pinch):

if (sb.length() > 4000) {
    Log.v(TAG, "sb.length = " + sb.length());
    int chunkCount = sb.length() / 4000;     // integer division
    for (int i = 0; i <= chunkCount; i++) {
        int max = 4000 * (i + 1);
        if (max >= sb.length()) {
            Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + sb.substring(4000 * i));
        } else {
            Log.v(TAG, "chunk " + i + " of " + chunkCount + ":" + sb.substring(4000 * i, max));
        }
    }
} else {
    Log.v(TAG, sb.toString());
}

Edited to show the last string!


Break it up in several pieces recursively.

public static void largeLog(String tag, String content) {
   if (content.length() > 4000) {
       Log.d(tag, content.substring(0, 4000));
       largeLog(tag, content.substring(4000));
   } else {
       Log.d(tag, content);
   }
}

There is a fixed size buffer in logcat for binary logs (/dev/log/events) and this limit is 1024 bytes. For the non-binary logs there is also a limit:

#define LOGGER_ENTRY_MAX_LEN        (4*1024)
#define LOGGER_ENTRY_MAX_PAYLOAD (LOGGER_ENTRY_MAX_LEN - sizeof(struct logger_entry))

So the real message size for both binary and non-binary logs is ~4076 bytes. The kernel logger interface imposes this LOGGER_ENTRY_MAX_PAYLOAD limit.

The liblog sources (used by logcat) also say:

  • The message may have been truncated by the kernel log driver.

I would recommend you the nxlog tool which does not use the logcat binary, but due to the limitations in the kernel I doubt that it will solve your problem. Nevertheless, it might be worth a try. (disclaimer: I'm the author.)


for( String line : logMesg.split("\n") ) {
    Log.d( TAG, line );
}