It’s not often I get to use a tweet by Many Tricks own Peter Maurer as the inspiration for a tip. But this tip is such a case, as he recently complained about Console and its inability to see old output. A response from @fzwob taught me something I didn’t know:
@petermaurer for logs from customers of your app on Sierra, use Terminal:
log show —predicate ‘processImagePath CONTAINS[c] “processname”’
— Friedrich Markgraf (@fzwob) March 25, 2017
That command browses the captured macOS log data and pulls out anything that matches the specified process name. This could be useful if you’re having troubles with an app and wonder if anything was logged relative to your troubles. Or you might be asked to send the log data if you’re working with the developer on your issue.
Unfortunately, the quotes and dashes in the command as tweeted have been prettified (by Twitter?); here it is in raw Terminal form, using our own Moom as an example:
log show --predicate 'processImagePath CONTAINS[c] "Moom"'
When you press Return, the command will start digging into the log file, and soon start spewing output—possibly a lot of output—to your screen.
Once the log file has been completely searched for your specified process, you’ll get the command prompt back.
To help trim the output, you can search for entries just from a given date or dates by adding --start and/or --end options to the command, like this:
log show --predicate 'processImagePath CONTAINS[c] "Moom"' --start "2017-03-18" --end "2017-03-22"
But just having this output in Terminal isn’t much help, especially if you need to send it to a developer. To capture the output to a file and see it onscreen, you need to pipe it to the tee command. For example, to capture the above date-specific search to a file named output.txt on your Desktop, you’d use this command.
log show --predicate 'processImagePath CONTAINS[c] "Moom"' --start "2017-03-18" --end "2017-03-22" | tee ~/Desktop/output.txt
You’ll still see lots of output fly by in Terminal, but it will also be captured to the specified file. If you don’t want to see it onscreen, you can just redirect the output, like this:
log show --predicate 'processImagePath CONTAINS[c] "Moom"' --start "2017-03-18" --end "2017-03-22" > ~/Desktop/output.txt
I doubt I’ll need this command often, but it’s nice to know you can get app-specific data from the log system.