Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ADB Logcat : tag with colon

How can I filter the output of adb logcat for a tag with a colon in it (with logcat only, not using grep or identical tools)?

e.g.:

adb logcat "SomeApp:Something:* *:S"

where "SomeApp:Something" is the specified tag.

I know that this symbol shouldn't be used in a tag, but unfortunately it's third party code, not ours...

Thank you in advance!

like image 834
Ricardo Sousa Avatar asked Oct 21 '22 16:10

Ricardo Sousa


1 Answers

I have to say it's a good question. I checked the code for logcat and found out that the parsing code for filter expression in logcat.cpp.

int android_log_addFilterRule(AndroidLogFormat *p_format,
        const char *filterExpression)
{
    size_t i=0;
    size_t tagNameLength;
    android_LogPriority pri = ANDROID_LOG_DEFAULT;

    tagNameLength = strcspn(filterExpression, ":");

    if (tagNameLength == 0) {
        goto error;
    }

    if(filterExpression[tagNameLength] == ':') {
        pri = filterCharToPri(filterExpression[tagNameLength+1]);

        if (pri == ANDROID_LOG_UNKNOWN) {
            goto error;
        }
    }

    ...

    return 0;
error:
    return -1;
}

The key point is logcat use strcspn(filterExpression, ":") to parse a tagname, so basically I'm afraid it is impossible to filter a tag with colon using logcat. However, you can find other ways.

I think the DDMS in eclipse can use regular expression to filter tag field, so you can go with very complicated REs if you like.

"SomeApp\:Something:* *:S"

You can even try some OR feature like:

^Something1$|^Something2$

If you don't want to use eclipse, you can try to read out the log by your own code, and parse them into different log records and log field. Then you can write a simple script to filter whatever you want. Hope this can help you.

like image 99
StarPinkER Avatar answered Oct 29 '22 20:10

StarPinkER