keepcalculator

06 Numbers and Powers

Console Logs Command Line Mac: How to View

Card No. 06·84592 · Updated · Standard formula, shown below

To view console logs from the command line on a Mac, you use the log command in Terminal. This built-in tool lets you stream, query, and export system and app logs without opening the Console app. You can filter by subsystem, process, time range, and even follow logs live as they are written.

Background: macOS Unified Logging

Since macOS 10.12 (Sierra), Apple replaced the old syslogd and system.log with a unified logging system. All system and app messages are stored in a compressed, binary format in /var/db/diagnostics and /var/db/uuidtext. The log command is the official way to read these logs from the terminal. Unlike the Console app, which shows a live stream, log gives you precise control over queries and can export data for analysis.

How the log Command Works

The log command has two primary subcommands:

  • log show – displays historical log entries over a time range.
  • log stream – shows new entries in real time, similar to tail -f.

Both accept a --predicate to filter entries. Predicates use NSPredicate syntax, so you can match on fields like process, subsystem, category, eventMessage, and senderImagePath. You can also combine conditions with AND, OR, and NOT.

Basic Usage Examples

Here are common commands you will actually type:

  • Show all logs from the last 10 minutes: log show --last 10m
  • Follow new logs live: log stream
  • Filter by process (e.g., Safari): log show --predicate 'process == "Safari"'
  • Filter by subsystem (e.g., networking): log show --predicate 'subsystem contains "network"'
  • Search for a specific string: log show --predicate 'eventMessage CONTAINS "error"'
  • Export to a file: log show --last 1h > ~/Desktop/logs.txt

You can combine flags: log show --last 30m --predicate 'process == "kernel" AND eventMessage CONTAINS "USB"'.

Common Problems and How to Fix Them

Three issues trip up most users:

  1. No output for a predicate. If you get zero results, the predicate may be case-sensitive or the field name may be wrong. Use log show --info --debug to include info and debug messages, which are hidden by default.
  2. Too much output. Pipe to grep or use a more specific predicate. For example, add --style compact to reduce formatting.
  3. Permission denied. Some logs require sudo. Run sudo log show ... and enter your password. This is normal for kernel-level logs.

If log itself seems broken, restart the logging daemon with sudo log config --mode "level:info" (this resets to default).

Comparing log, Console, and syslog

The log command is the modern replacement for syslog and tail -f /var/log/system.log. The Console app (in /Applications/Utilities) is a GUI wrapper around the same data. Key differences:

  • log is scriptable and faster for filtering.
  • Console shows a live stream with a search box but less precise predicates.
  • Legacy syslog commands still work for compatibility but do not see unified logs.

For most troubleshooting, log is the better choice because you can copy-paste exact commands to share with others.

Costs and Safety

The log command is free and built into macOS. There are no costs. Safety-wise, reading logs is safe; you cannot damage your system by viewing them. However, be careful with sudo log erase (which deletes all logs) – do not run that unless you intend to reset logging. Also, logs may contain sensitive information like file paths or IP addresses; avoid sharing full logs publicly.

Alternatives to the Command Line

If you prefer a GUI, the Console app shows the same unified logs. For advanced analysis, you can export logs as .logarchive and open them in Console. Third-party tools like lnav (installed via Homebrew) can also read log files, but they do not access the unified log directly – you must export first with log show.

Frequently Asked Questions

How do I see live console logs in Terminal?

Run log stream in Terminal. It will print new log entries as they happen. To stop, press Control+C. Add --predicate to filter, e.g., log stream --predicate 'process == "Safari"'.

Why does log show return nothing?

Most likely the predicate is too restrictive or you are missing info-level messages. Add --info --debug to include all levels. Also check the time range – --last 1m may be too short if the system was idle.

Can I use grep with log show?

Yes, you can pipe: log show --last 1h | grep "error". This is simpler than writing a predicate, but it is slower because it processes all output. For large logs, a predicate is more efficient.

How do I save console logs to a file?

Use redirection: log show --last 1h > ~/Desktop/log.txt. For a live stream, use log stream > ~/Desktop/live.log and stop with Control+C. The file will be plain text.

What is the difference between log show and log stream?

log show prints historical entries that are already stored. log stream waits for new entries and prints them as they occur. Use show for past events, stream for live monitoring.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →