Can we turn off "chatty" in logcat? [duplicate]
Asked Answered
S

2

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?

Szeged answered 3/5, 2016 at 13:48 Comment(4)
Might be some interesting background on the M issues here: github.com/JakeWharton/pidcat/issues/102Tetrameter
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 ?Szeged
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.Tetrameter
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.Szeged
F
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 ""
Fiddlededee answered 23/8, 2016 at 3:44 Comment(6)
Documentation: developer.android.com/studio/command-line/logcat.htmlIntisar
This looks quite useful, you can actually whitelist and blacklist the logs. ThanksSzeged
Doesn't work for meContortion
@SantoshSalunke Can you be more specific? What happens? Error messages?Fiddlededee
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 OnePlus5Contortion
This doesn't work.Ballentine
D
-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
}  
}
Doting answered 3/5, 2016 at 14:49 Comment(1)
This is interesting, but I'm not sure how it solves my problem.Szeged

© 2022 - 2024 — McMap. All rights reserved.