23.4 · Unified logging: Logger, levels, privacy and reading logs back
Logging is how you debug what you cannot attach a debugger to: the user’s device, a background launch, a race that disappears when you pause. The unified logging system is cheap and structured, so use it instead of print.
Mental model. Log events with a level, a subsystem and a category, mark anything personal as private, and read it back with the tool that fits (Xcode, Console, the log command or OSLogStore).
Logger
The API, levels, subsystem and category, privacy, and reading logs.
- How does the unified logging system work: Logger, levels, subsystems and categories, privacy, and how do you read logs back?
print writes to standard output, which exists only under Xcode and is lost on a user’s device. Unified logging (os.Logger, import OSLog) writes structured…
More in Debugging & Instruments
- 23.1 · LLDB and breakpoints
- 23.2 · The view debugger, network inspection and memory bugs
- 23.3 · Sanitizers, and bugs that only appear in Release
- 23.5 · Crash reports, symbolication and a production diagnostics pipeline
- 23.6 · Console, sysdiagnose and reproducing a bug
- 23.7 · Schemes, test plans, simulators and derived data
- 23.8 · Reading sanitizer output, exit codes and runtime traps
- 23.9 · Diagnosing a hang, malloc debugging and leaks from the command line
- 23.10 · Demangling, atos and empty dSYMs, and log formatting