'Has anyone managed to filter logs in the macos `log stream` command using pid?
I've been wrecking my brain trying to get the log stream command on macos to work with a passed in pid.
I have an app FooBar with a pid 12345.
The command:
log stream --debug --info --process FooBar
Works perfectly fine. On using ps auf | grep "FooBar" or the Activity Monitor to get the app's pid, and then doing the below command:
log stream --debug --info --process 12345
I never get any logs. Can anyone please tell me if I'm doing something wrong? I can't find any example of anyone actually using the pid online.
Solution 1:[1]
Apple's log facility allows selecting the relevant messages with its "predicate-based filtering". It enables quite elaborate filtering via:
log stream --predicate 'PREDICATE BASED FILTER'
The PREDICATE BASED FILTER is an expression in the predicate DSL, which is outlined here. Fields specific to the log facility are available via
log help predicates
Predicate-based filtering is quite powerful, but unfortunately it can get verbose. It seems that Apple wanted to "elevate" some of the common predicates into the top-level flags.
log --process ProcessName
is an example of such "elevated" predicate. Its full form is
log --predicate 'process == "ProcessName"'
Unfortunately, there's no "elevated" predicate for filtering via pid, but it's supported via the full predicate syntax:
log --predicate 'processID == 12345'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | oesh |
