Android Log Message Truncation

Frustrated by Android’s inability to log messages over 4k? In my case, I had some heft SOAP messages that were getting cut off. The simple solution is to use System.out.println(), but that always logs at the info level. Here’s something neater,

    void v(String msg) {
      println(Log.VERBOSE, msg);

    void d(String msg) { ... }
    void i(String msg) { ... }
    void w(String msg) { ... }
    void e(String msg) { ... }

    private int println(int priority, String msg) {
        int l = msg.length();
        int c = Log.println(priority, TAG, msg);
        if (c < l) {
            return c + println(priority, TAG, msg.substring(c+1));
        } else {
            return c;

In short, take advantage of the fact that the low-level Log.println() call returns the number of bytes written. Use that fact to recursively call ourselves until we log all of the message.

3 Responses to Android Log Message Truncation

  1. Sam says:

    Thanks. I think you have a typo in line 14 — the TAG argument should be removed, correct?

    • Sam says:

      Even with my suggested change, this code does not work, unfortunately. It looks like the count returned by Log.println() includes extra log entry text that is not in the passed-in msg. So, this code will drop some characters between chunks.

      • Sam says:

        Actually, looking in another forum, it looks like the real problem is that Log.println() returns a byte count, not a character count.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: