Android Log Message Truncation

2012/09/08

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.

Advertisements

aLogcat – Android Logcat Application

2009/11/30

aLogcat market barcode

There are several “log view” applications on the market. All of them provide a means to send your log file contents, typically via email. This is one good approach, but it doesn’t handle the use case where you don’t have immediate access to a PC email client to view the results. aLogcat is an Android application that allows you to view your Android device log from the device itself. It provides a scrolling, color-coded log that is filterable by keyword and log level. It also supports output in various log formats. aLogcat also covers the send log use case by allowing a snapshot of the log to be sent off to another device.

This is mainly an app for developers, but it is also useful for power users that are willing to get involved with developers to help them find problems in their applications. Most Android developers are small scale hobbyists and can’t devote full-time effort and money to rigorous testing across multiple devices. I hope this app lowers the barrier for involvement of the average user in the development cycle.

aLogcat