18

So I'm trying to find an elusive bug in a large codebase. As such, I've put a lot of logging into my app. I'm lucky enough to have multiple testers working on this. However, I've found that a lot of my logcat logs are missing. They're hidden as 'chatty'. For example

1799 12017 I logd: uid=10007 chatty comm=Binder_B, expire 4 lines

I've found some mention of using the adb command

adb logcat -p

but I can't find any documentation for the -p. I've also found that with a lot of devices (possibly all devices on Marshmallow) this is not supported.

Other than having the device plugged into Android Studio / Eclipse, is there a way to stop 'chatty' from hiding my logs?

4
  • Might be some interesting background on the M issues here: github.com/JakeWharton/pidcat/issues/102
    – stkent
    May 3, 2016 at 14:01
  • I had seen this, but wasn't sure what to make of it. Does this mean that the Marshmallow equivalent of adb logcat -p is adb logcat -v brief | pidcat ? May 3, 2016 at 15:51
  • pidcat itself is not relevant here - it's a wrapper around logcat that makes the output easier to read - but somewhere in their codebase they had to deal with a change in logcat behavior introduced in Android M. If you can find that issue/change it might give some insight into different behaviors on M/pre-M.
    – stkent
    May 3, 2016 at 17:00
  • Thanks. This does make sense, but I can't really tell if this change affects -p since I can't find any information on what the option does. May 4, 2016 at 8:53

2 Answers 2

8

I also can't find documentation, but according to Issue 202457 - android - Disable chatty filtering of log messages (I/chatty ... expire N lines) - Android Open Source Project - Issue Tracker the command you want is

adb logcat -P ""
6
  • 1
    Documentation: developer.android.com/studio/command-line/logcat.html
    – DrChandra
    Aug 8, 2017 at 14:14
  • 1
    This looks quite useful, you can actually whitelist and blacklist the logs. Thanks Aug 9, 2017 at 13:20
  • 8
    Doesn't work for me
    – srs
    Apr 28, 2018 at 2:44
  • 4
    I don't get any error message. After this executing this command adb logcat -P "" , it does not disable chatty. I tried mentioning my app's UID/PID, it gets whitelisted but still chatty is not disabled. My device is OnePlus5
    – srs
    May 2, 2018 at 17:10
  • 7
    This doesn't work.
    – Matt
    Oct 17, 2019 at 19:58
-2

I've created my own debugger and DEBUG_MODE & DEBUG_WITH_STACKTRACE_MODE are enabled true in build.gradle debug{} and false bydefault

public class AppLoger {
      public static boolean DEBUG_MODE = BuildConfig.LOG_DEBUG_MODE;
public static boolean DEBUG_WITH_STACKTRACE_MODE =     BuildConfig.LOG_DEBUG_WITH_STACKTRACE_MODE;

/**
 * @param cls     Class<T>
 * @param message String
 * @author Android Lead
 */
public static <T> void logInfo(Class<T> cls, String message) {
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) {
        String tag = cls.getName();
        Log.i(tag, "-----");
        Log.i(tag, LogType.INFO + ": " + message);
        if (DEBUG_WITH_STACKTRACE_MODE) {
            Log.i(tag, getStackTrace());
        }
    }
}

/**
 * @param cls     Class<T>
 * @param message String
 * @author Android Lead
 */
public static <T> void logWarning(Class<T> cls, String message) {
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) {
        String tag = cls.getName();
        Log.w(tag, "-----");
        Log.w(tag, LogType.WARNING + ": " + message);

        if (DEBUG_WITH_STACKTRACE_MODE) {
            Log.w(tag, getStackTrace());
        }
    }
}

/**
 * @param cls     Class<T>
 * @param message String
 * @author Android Lead
 */
public static <T> void logError(Class<T> cls, String message) {
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) {
        String tag = cls.getName();
        Log.e(tag, "-----");
        Log.e(tag, LogType.ERROR + ": " + message);

        if (DEBUG_WITH_STACKTRACE_MODE) {
            Log.e(tag, getStackTrace());
        }
    }
}

/**
 * @param cls     Class<T>
 * @param message String
 * @author Android Lead
 */
public static <T> void logError(Class<T> cls, String message, Throwable e) {
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) {
        String tag = cls.getName();
        Log.e(tag, "-----");
        Log.e(tag, LogType.ERROR + ": " + message, e);

        if (DEBUG_WITH_STACKTRACE_MODE) {
            Log.e(tag, getStackTrace());
        }
    }
}

/**
 * @param tag String
 * @param msg String/JSON/ArrayList
 * @author Android Lead
 */
public static void e(String tag, Object msg) {
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE)
        Log.e(tag, "" + msg);
}

/**
 * @param tag String
 * @param msg String/JSON/ArrayList
 * @author Android Lead
 */
public static void i(String tag, Object msg) {
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE)
        Log.i(tag, "" + msg);
}

/**
 * @author Android Lead
 */
private static String getStackTrace() {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    new Throwable().printStackTrace(pw);
    return sw.toString();
}

private enum LogType {
    INFO, WARNING, ERROR
}  
}
1
  • 6
    This is interesting, but I'm not sure how it solves my problem. May 3, 2016 at 16:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.