With the introduction of "Unified Logging" in macOS 10.12 Sierra, one can use the log
command to view system log messages in a terminal. For example
sudo log stream
or
sudo log stream --process `pgrep -f /usr/local/bin/myprogram` --info --debug
or
log show --predicate 'process == "myprogram"' --last 1h --info --debug
Using the new "unified" Console.app, one can view system messages and can also view messages from connected iOS devices.
Is there any way to use the log
command or any other command-line interface to view iOS device messages in Terminal, or to send them to a file? Or is Console.app the only way?
In short, os_log makes it possible for you to add logs to your application in a more structured way. It allows you to filter your logs in the Console. app application. This way, you get a better view on why a certain error occurred. You can see it as an advanced version of the Xcode Console.
In the Console app on your Mac, type a search phrase, then press Return. To search activities, click the Activities button in the toolbar (or use the Touch Bar). Log messages or activities that fit the search criteria appear in the Console window.
tl;dr: log collect —device
log collect --device
lets you retrieve log archives that can be passed into log show --archive system_logs.logarchive
with all the options you're familiar with.
Use log collect --device
to automatically guess the device you're referring to. log collect device-name="Maxs iPhone"
or log collect device-udid=abcdefg
to collect from a particular device.
log collect --output /your/path
will save it to your specified file name or directory. If --output
is not given, your output will be in the current directory as system_logs.logarchive
.
Note: I occasionally get errors about log: failed to create archive: Device not configured (6)
or log: failed to create archive: Connection reset by peer (54)
but if I just rerun the command it'll sometimes work 🤷🏾♀️
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With