如何使用 Android adb logcat 按标记名称排除某些消息?

发布于 2024-10-29 04:32:48 字数 86 浏览 5 评论 0原文

Logcat 允许过滤日志,但它的工作原理如下:您定义过滤器,logcat 仅显示与过滤器匹配的消息。但是有没有办法显示除过滤器定义的一些标签之外的所有日志?

Logcat allows filtering logs but it works like that: You define filters and logcat only displays messages which matches filters. But is there a way to display all logs EXCEPT some TAGs defined by filters?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

梦里泪两行 2024-11-05 04:32:49

在 shell 中,您可以使用如下命令:

adb logcat AlarmManagerService:S PowerManagerService:S *:V

它将包含除带有 AlarmManagerServicePowerManagerService 标记的日志之外的所有日志。

:S 代表“silent”,这意味着这些标签不会打印任何内容;:V 代表“verbose”,这意味着将为所有标签打印所有内容logcat 的 Android 文档 提供了您可以在过滤器中使用的其他选项的更多详细信息。 .)

您还可以使用ANDROID_LOG_TAGS 环境变量设置默认过滤器,例如(在 bash 中):

export ANDROID_LOG_TAGS="AlarmManagerService:S PowerManagerService:S *:V"

From the shell, you can use a command like:

adb logcat AlarmManagerService:S PowerManagerService:S *:V

which will include all logs apart from those with the AlarmManagerService and PowerManagerService tags.

(The :S stands for "silent", which means nothing will be printed for those tags; the :V stands for "verbose" which means everything will be printed for all other tags. The Android documentation for logcat has more details of other options you can use in the filters.)

You can also use the ANDROID_LOG_TAGS environment variable to set up default filters, e.g. (in bash):

export ANDROID_LOG_TAGS="AlarmManagerService:S PowerManagerService:S *:V"
初见你 2024-11-05 04:32:49

^(?!.*(WindowManager|dalvik|Environment|DataRouter|AlarmManager)).*$

这将排除内容为 WindowManager,dalvik,... 的文本

tag:^(?! .*(WindowManager|dalvik|Environment|DataRouter|AlarmManager)).*$

这将从 logcat 中排除标签 WindowManager,dalvik,...

^(?!.*(WindowManager|dalvik|Environment|DataRouter|AlarmManager)).*$

This will exclude texts having contents WindowManager,dalvik,...

tag:^(?!.*(WindowManager|dalvik|Environment|DataRouter|AlarmManager)).*$

This will exclude tags WindowManager,dalvik,... from logcat

顾挽 2024-11-05 04:32:49

结合正向和负向前瞻以实现更强大的过滤。

示例:

(?=(AndroidRuntime|Main|RandomTag))(?!(Audio))

包含第一个嵌套括号中的标签。

第二个标签被排除。

Combine both positive and negative lookahead for more powerful filtering.

Example:

(?=(AndroidRuntime|Main|RandomTag))(?!(Audio))

Tags in the first nested parentheses are included.

Tags in second are excluded.

心碎的声音 2024-11-05 04:32:49

对于新的 LogcatV2,您应该使用此示例:

-tag~: chatty|WifiHAL|HwBinder|Light|lsc_nvram|SensorService|thermal_repeater

等等

With new LogcatV2 you should use this example:

-tag~: chatty|WifiHAL|HwBinder|Light|lsc_nvram|SensorService|thermal_repeater

and so on

爱人如己 2024-11-05 04:32:49

还可以选择在 Android Studios logcat GUI 中创建自己的过滤器。
例如,我对 logcat 中的 OpenGLRenderer 和 ViewRoot 消息感到非常恼火。

在 logcat 中,单击“编辑过滤器配置”并创建一个新过滤器。
在日志标签输入中,您可以输入类似 ^(?!.*(OpenGLRenderer|ViewRoot)) 的内容,并添加其他几个让您烦恼的标签。

logcat 过滤器

There is also the option to make your own filter in Android Studios logcat GUI.
E.g. I was very annoyed by OpenGLRenderer and ViewRoot messages in logcat.

In the logcat click on Edit Filter Configuration and create a new filter.
In the Log Tag Input you can type in something like ^(?!.*(OpenGLRenderer|ViewRoot)) and add several other Tags that are annoying you.

Filter for logcat

横笛休吹塞上声 2024-11-05 04:32:49

以下是我用来忽略三星系统日志的过滤器列表。也可以与其他设备一起使用。

Logcat->编辑过滤器配置 ->日志标签

^(?!(PowerUI|PowerPlanningReceiver|BatteryService|SamsungPhoneWindowManager|MotionRecognitionService|AudioService|APM_AudioPolicyManager|SensorService|StorageManager|SignalClusterView|BatteryService|TelephonyManager|UsbDeviceManager|KeyguardUpdateMonitor|BatteryController|ActivityManager|LauncherAppsService|AppsModel|DataLoader|PackageManager|LauncherApps|ContactsImsCommon|ImsUtil|ImsSettingsProvider|DeviceConfigManager|WifiService|BackupManagerService|PersonaManagerService|DefaultDialerManager|ResourceType|NetworkUIGlobals|NetworkProxy|FileWriteThread|ReflectUtil|PhoneApp|SamsungAlarmManager|display|DeviceStorageMonitorService|wrapperGPS|io_stats|GnssLocationProvider|KeyguardServiceBoxContainer|ConnectivityService|SSRM|TLC_TIMA_PKM_initialize|mc_tlc_communication|TeeDriverClient|TLC_TIMA_PKM_measure_kernel|AutomaticBrightnessController|BatteryUtils|WifiConnectivityManager|Launcher|IconView|ApplicationPackageManager|LiveIconLoader|WifiScanningService|WifiHAL|WifiScanController|ApplicationPolicy|SELinux|TimaKeyStoreProvider|ActivityThread|zygote|GservicesProvider|GoogleHttpClient|cr_ChildProcessConnect|WificondControl|Netd|Tethering|ContactsImsCommon|ImsConstants|tnet-jni|BatteryStatsService|SignalClusterView|LiveIconManager|BitmapCacheContainer|com.samsung.android.app.powerplanning.utils.BatteryUtils|ReflectField|cr_ChildConnAllocator|TinLoadingFailTracker|WifiPermissionsUtil|EventHandler_FLP|[email protected]|BluetoothAdapter|bt_btm|WifiPermissionsUtil|GeofencerStateMachine|Places|GCoreUlr|BeaconBle|Sensors|SLocation|ContactsProvider_EventLog|WificondScannerImpl|AlarmManager|AlarmManagerEXT|MultiDex|NetworkSecurityConfig|DnsProxyListener|dalvik-internals|mobileconfig|SsacManager|ImsPhoneStateManager|VolteServiceModule|PdnController|PowerManagerService|GameManagerService|NoSync|SensorManager|DisplayPowerController|NetworkController|SamsungAnalytics111040|tlcFidoAuthnr|InputReader|FlashlightController|KeyguardWallpaperController|OpenGLRenderer|EasyMuteController|Vibrator|VibratorService|PowerManagerUtil|LightsService|WindowManager|InputDispatcher|InputReader|CustomFrequencyManagerService|SystemUIAnalytics|SamsungAnalytics|swipe|PanelView|BadgeCache|MARsPolicyManager|MARsDBManager|KeyguardClockPage|ScanManager|RegiMgrBase|secImsManager|GeolocationController|MultiSimUtils|CarrierText|Mms|NetworkNotificationUI2|CommandListener|ReschedulableTimer|RCS-ContactsImsCommon|Settings|DmConfigModule|NotificationMgr2|PhoneMultiSimUtils|PhoneProxy|VideoCapabilities|AudioCapabilities|SAIV_FACE|FaceController|FaceService|SamsungAnimationCreator|ImageWallpaper|Finsky|VirtualScreen|PagedView|DragLayer|HomeContainer|ImsServiceStub|DmConfigHelper|TZ))

Here's a list of filters that I've been using to ignore Samsung system logs. would work with other devices too.

Logcat -> Edit Filter Configuration -> Log Tag

^(?!(PowerUI|PowerPlanningReceiver|BatteryService|SamsungPhoneWindowManager|MotionRecognitionService|AudioService|APM_AudioPolicyManager|SensorService|StorageManager|SignalClusterView|BatteryService|TelephonyManager|UsbDeviceManager|KeyguardUpdateMonitor|BatteryController|ActivityManager|LauncherAppsService|AppsModel|DataLoader|PackageManager|LauncherApps|ContactsImsCommon|ImsUtil|ImsSettingsProvider|DeviceConfigManager|WifiService|BackupManagerService|PersonaManagerService|DefaultDialerManager|ResourceType|NetworkUIGlobals|NetworkProxy|FileWriteThread|ReflectUtil|PhoneApp|SamsungAlarmManager|display|DeviceStorageMonitorService|wrapperGPS|io_stats|GnssLocationProvider|KeyguardServiceBoxContainer|ConnectivityService|SSRM|TLC_TIMA_PKM_initialize|mc_tlc_communication|TeeDriverClient|TLC_TIMA_PKM_measure_kernel|AutomaticBrightnessController|BatteryUtils|WifiConnectivityManager|Launcher|IconView|ApplicationPackageManager|LiveIconLoader|WifiScanningService|WifiHAL|WifiScanController|ApplicationPolicy|SELinux|TimaKeyStoreProvider|ActivityThread|zygote|GservicesProvider|GoogleHttpClient|cr_ChildProcessConnect|WificondControl|Netd|Tethering|ContactsImsCommon|ImsConstants|tnet-jni|BatteryStatsService|SignalClusterView|LiveIconManager|BitmapCacheContainer|com.samsung.android.app.powerplanning.utils.BatteryUtils|ReflectField|cr_ChildConnAllocator|TinLoadingFailTracker|WifiPermissionsUtil|EventHandler_FLP|[email protected]|BluetoothAdapter|bt_btm|WifiPermissionsUtil|GeofencerStateMachine|Places|GCoreUlr|BeaconBle|Sensors|SLocation|ContactsProvider_EventLog|WificondScannerImpl|AlarmManager|AlarmManagerEXT|MultiDex|NetworkSecurityConfig|DnsProxyListener|dalvik-internals|mobileconfig|SsacManager|ImsPhoneStateManager|VolteServiceModule|PdnController|PowerManagerService|GameManagerService|NoSync|SensorManager|DisplayPowerController|NetworkController|SamsungAnalytics111040|tlcFidoAuthnr|InputReader|FlashlightController|KeyguardWallpaperController|OpenGLRenderer|EasyMuteController|Vibrator|VibratorService|PowerManagerUtil|LightsService|WindowManager|InputDispatcher|InputReader|CustomFrequencyManagerService|SystemUIAnalytics|SamsungAnalytics|swipe|PanelView|BadgeCache|MARsPolicyManager|MARsDBManager|KeyguardClockPage|ScanManager|RegiMgrBase|secImsManager|GeolocationController|MultiSimUtils|CarrierText|Mms|NetworkNotificationUI2|CommandListener|ReschedulableTimer|RCS-ContactsImsCommon|Settings|DmConfigModule|NotificationMgr2|PhoneMultiSimUtils|PhoneProxy|VideoCapabilities|AudioCapabilities|SAIV_FACE|FaceController|FaceService|SamsungAnimationCreator|ImageWallpaper|Finsky|VirtualScreen|PagedView|DragLayer|HomeContainer|ImsServiceStub|DmConfigHelper|TZ))
百合的盛世恋 2024-11-05 04:32:49

执行此操作的一个简单方法是仅过滤您想要查看的标签。

adb logcat -s "Tag1" -s "Tag2" -s "Tag3"

只会显示那些标签。

An easy way to do this is by simply filtering in only the tags you want to see.

adb logcat -s "Tag1" -s "Tag2" -s "Tag3"

Will bring up only those tags.

往事风中埋 2024-11-05 04:32:49

这是我收集的最常见的烦人标签

^(?!.*(OpenGLRenderer|ViewRoot|ForceDarkHelper|Looper|PlayCore|AudioTrack|SurfaceUtils|cr_ChildProcessConn|FA|ActivityThread|DynamiteModule|Perf|DynamitePackage|EgretLoader|cr_LibraryLoader|BpBinder|chatty|FeatureParser|MediaCodec|ExtendedACodec|MapperHal|OMXClient|VideoCapabilities|Gralloc3|MetadataUtil|AdrenoGLES|chromium|DpmTcmClient|WebViewFactory|cr_CachingUmaRecorder|AdrenoUtils|cr_media|AudioManager|cr_SpareChildConn|Chrome_InProcGp|Choreographer|AdInternalSettings|Keep-Alive|Vary|pool-15-thread-|WifiMulticast|WifiHW|MtpService|PushClient|EGL_emulation|OpenGl*|InputReader|art|dalvik|Environment|DataRouter|AlarmManager|WindowManager|PhoneStatusBar|ActivityManager|ResourceType|PackageManager|gralloc|Gnss|NetRec|ResolverController|GAv4|AsyncOperation|AppOps|WificondControl|aofp|wifi|netmgr|ctxmgr|BestClock|FirebaseInstanceId|android.os.Debug|memtrack|netd|system_server|StrictMode|bluetooth|NetworkMonitor|FA|BroadcastQueue|ConnextivityService|WakeLock|HttpClientWrapper|RAWR|Tenor|BgTask|WifiService|BluetoothAdapter|UpdateStatsService|AppIdleHistory|Connectivity|VelvetNetworkClient|WorkerManager|EGL_emulation|chatty|gralloc|InputReader|ActivityThread|ActivityTaskManager|UsageStatsService|ocess.gservice|DropBoxManagerService|EventLogChimeraService|PContextMetricsRunner))

This is The Most common Annoying Tags i gathered

^(?!.*(OpenGLRenderer|ViewRoot|ForceDarkHelper|Looper|PlayCore|AudioTrack|SurfaceUtils|cr_ChildProcessConn|FA|ActivityThread|DynamiteModule|Perf|DynamitePackage|EgretLoader|cr_LibraryLoader|BpBinder|chatty|FeatureParser|MediaCodec|ExtendedACodec|MapperHal|OMXClient|VideoCapabilities|Gralloc3|MetadataUtil|AdrenoGLES|chromium|DpmTcmClient|WebViewFactory|cr_CachingUmaRecorder|AdrenoUtils|cr_media|AudioManager|cr_SpareChildConn|Chrome_InProcGp|Choreographer|AdInternalSettings|Keep-Alive|Vary|pool-15-thread-|WifiMulticast|WifiHW|MtpService|PushClient|EGL_emulation|OpenGl*|InputReader|art|dalvik|Environment|DataRouter|AlarmManager|WindowManager|PhoneStatusBar|ActivityManager|ResourceType|PackageManager|gralloc|Gnss|NetRec|ResolverController|GAv4|AsyncOperation|AppOps|WificondControl|aofp|wifi|netmgr|ctxmgr|BestClock|FirebaseInstanceId|android.os.Debug|memtrack|netd|system_server|StrictMode|bluetooth|NetworkMonitor|FA|BroadcastQueue|ConnextivityService|WakeLock|HttpClientWrapper|RAWR|Tenor|BgTask|WifiService|BluetoothAdapter|UpdateStatsService|AppIdleHistory|Connectivity|VelvetNetworkClient|WorkerManager|EGL_emulation|chatty|gralloc|InputReader|ActivityThread|ActivityTaskManager|UsageStatsService|ocess.gservice|DropBoxManagerService|EventLogChimeraService|PContextMetricsRunner))
九厘米的零° 2024-11-05 04:32:49

在 Eclipse Logcat 视图中没有这样的选项。但是,您可以利用日志级别来排除日志级别太低的任何消息。例如将其设置为 I(nfo) 不会显示 D(ebug) 和 (V)erbose 消息。

Within the Eclipse Logcat view there's not such an option. However you can make use of the log level to exclude any message whose log level is too low. E. g. setting it to I(nfo) doesn't display D(ebug) and (V)erbose messages.

滥情空心 2024-11-05 04:32:48

您可以在 DDMS Monitor(以及 Eclipse 或 Android Studio)中使用正则表达式输入框和 执行此操作负面的前瞻断言,例如,我使用以下内容从日志中排除了很多噪音:(

tag:^(?!(WifiMulticast|WifiHW|MtpService|PushClient))

“tag:”不是正则表达式的一部分,但告诉 LogCat 仅将正则表达式应用于如果您在保存的过滤器中使用此技巧,则只需将正则表达式放入“标记”输入框中,并省略“tag:”前缀)

在Android Studio的logcat监视器窗格中,您可以设置保存的过滤器为此,请打开右上角的下拉菜单(可能选择了“仅显示选定的应用程序”)并选择“编辑过滤器配置”。创建一个新的 logcat 过滤器,并将 ^(?!(WifiMulticast ...etc. )) 放入“日志标签”框中,并使用 Regex复选框已选中。

You can do this from within DDMS Monitor (and also Eclipse or Android Studio) with the regular expression input box and negative look-ahead assertions, for example I am excluding a lot of noise from my log with the following:

tag:^(?!(WifiMulticast|WifiHW|MtpService|PushClient))

(The "tag:" isn't part of the regular expression, but tells LogCat to only apply the regex to the Tag field. If you use this trick in a saved filter then put just the regular expression in the "Tag" input box, and omit the "tag:" prefix)

In Android Studio's logcat monitor pane, you can set up a saved filter for this by opening the dropdown in the upper right (it may have "Show only selected application" selected) and selecting Edit Filter Configuration. Create a new logcat filter and put ^(?!(WifiMulticast ...etc. )) in the Log Tag box, with the Regex checkbox checked.

池予 2024-11-05 04:32:48

如果你想在Android studio中通过标签名称排除或过滤某些消息,请转到LogCat窗口=>编辑过滤器配置,然后在“by Log Tag(regex):”下输入以下内容:

^(?!(tag1|tag2|tag3|tag4))

注意没有空格,这是重要的

If you want to exclude or filter certain messages by tag name in Android studio, goto the LogCat window=>Edit Filter configuration, and enter the following under "by Log Tag(regex): "

^(?!(tag1|tag2|tag3|tag4))

Note that there are no spaces, this is important

情感失落者 2024-11-05 04:32:48

如果您使用的是 adb logcat,您可以通过 grep 进行管道传输并使用它的反向匹配:
grep 手册页

v, --invert-match
反转匹配的意义,以选择不匹配的行。

例如:

$adb logcat | grep --invert-match 'notshownmatchpattern' 

您可以使用正则表达式来扩展它。

下面是此类表达式的一个示例:

"/^(?:emails|tags|addresses)"

该表达式将检查给定的任一情况是否发生,然后 grep 不会列出它们。

If you are using adb logcat you could pipe it through grep and use it's inverted matching:
From the grep manpage:

v, --invert-match
Invert the sense of matching, to select non-matching lines.

For example:

$adb logcat | grep --invert-match 'notshownmatchpattern' 

You can extend this by using regular expressions.

Here is an example of such an expression:

"/^(?:emails|tags|addresses)"

This one would check for either of the given to occur, grep would then not list them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文