2

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.

Willeke
  • 14,578
  • 4
  • 19
  • 47
gran_profaci
  • 8,087
  • 15
  • 66
  • 99

1 Answers1

4

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'
oesh
  • 41
  • 2