Unified Logging and Activity Tracing
Show Apple's description.
The new Unified Logging and Tracing System for iOS and macOS uses Activity Tracing for performance, consolidates kernel and user-space logging, and has many other improvements. Learn how Logging and Tracing can help you debug and troubleshoot issues with your apps.
- One common, efficient logging mechanism for both user and kernel mode.
- Maximize information collected while minimizing observer effect (e.g. because of breakpoints/print you change the timing and the bug doesn't happen anymore).
os_logcompresses data, and defers lots of work (key point to avoid observer effect)
- Designed with privacy in mind ️❤️
- New tools to categorize and filter log messages
- Logging system collects caller info for you (
_FUNCTION__etc are automatically collected)
- New type formatters (more on this later)
- New console and command-line tool
Legacy APIs (
NSLog) are automatically redirected into the new system.
New File Format
/var/db/diagnosticswith additional support files at
.logarchiveis basically a merge of the files found in the folders above, it's used to transfer the logging to other people, bug reports
Subsystem and Categories
- Subsystem should be the app/framework domain (your.app.identifier)
- Category are the different domains (“store”, “chat”, “account”, ...)
Three basic levels:
Two special levels:
Each basic level has two characteristics that can be set for system, subsystem, or category (in the Console app we can mute every single one of them, even the process, even filter by type like error -> you can even save one filter that you create ):
- Enabled (does it actually produce a log?)
isItStoredToDiskor Memory (memory: memory buffer, saved to disk only on fault or error)
Levels are hierarchical, therefore by setting Debug to go to disk, implies that Info (and Default) will also go to disk
- Prevent accidental logging of Personally Identifiable Information (PII)
- Dynamic strings, collections, arrays, etc. are assumed to be private
Faults and Errors
Faults and Error log information are captured into a separate set of log files
- Errors represent issues discovered within a given application/library
- Faults represent more global problems in the system
- takes two parameters: the name of the subsystem and the name of the category.
- creates a thread-safe singleton object that controls behavior of log messages, here's how to use it:
We should use these as much as possible as these conversions will be done in the background for us (no observer effect!)
More information here.
Log Command Line Tool
More info here.