where are logcat filters applied?

2019-07-18 21:54发布

问题:

I have a single android device attached to the pc and have opened multiple shells which show logcat information. Everyone running with its specific filter. So my question is now, where are those filters applied? Already on the phone so only the filtered messages are sent over usb. Or are they applied on the pc on the adb server or client? I just want to prevent having multiple unfiltered logcat streams running simultaneous over the usb since I have limited bandwitdh. Thanks

回答1:

The data is pulled out of kernel buffers with the logcat command on the device. If you run

% adb logcat -\?

you can see the usage info, which includes a description of "filterspecs". These can be set on the command line, or by setting the ANDROID_LOG_TAGS. For example:

% adb logcat '*:W'

will show you only messages at Warning or Error level.

The trick here is that adb logcat is just shorthand for adb shell logcat, with the added bonus of propagating your ANDROID_LOG_TAGS environment variable to the device. The filtering is being done by the logcat command, which is just dumping text output over adb. The output from the logcat command doesn't get any special treatment.

So the answer to your question is: the filtering happens on the device, individually for each window.

DDMS works differently.



回答2:

Or are they applied on the pc on the adb server or client?

They are applied by whatever application is presenting the LogCat information.



回答3:

Android stores log information on the device into 4 different buffers (Event Log, System Log, Radio Log, Main Log). After that adbd daemon can access this information and send it to the client. Thus, only on the client side you have ability to filter the information because on the phone all the information is stored.



回答4:

Currently it is not Possible for same build running on different devices.If u Have different builds then you can apply filter according to device name or version.

As U want to do this then it may achieve by some tricks. Log.v(LOG_TAG,"message"); In your LOG_TAG append device ID ,Which may be identified through TelephonyManager.

And add filter using it.



回答5:

The filters are applied on the phone. So of you enter a filter for a non existent logcat tag then no traffics goes over the usb. But each logcat opened with a cmd shell creates a new stream which increases the total traffic.