Logging
Capture telemetry from your app for debugging and performance analysis using the unified logging system.
Overview
When debugging problems in your app, it’s helpful to record the exact sequence of events that occurred, along with supplemental data about those events. Log messages provide a continuous record of your app’s runtime behavior, and make it easier to identify problems that can’t be caught easily using other techniques. Specifically, you might use log messages:
When you are unable to attach a debugger to the app, such as when you’re diagnosing problems on a user’s machine.
When the problem is intermittent, and is difficult to catch in the debugger.
When you want to get a general sense of your app’s behavior—for example, you want to know when certain tasks start and end.
The unified logging system provides a comprehensive and performant API to capture telemetry across all levels of the system. This system centralizes the storage of log data in memory and on disk, rather than writing that data to a text-based log file. You view log messages using the Console app, log command-line tool, or Xcode debug console. You can also access log messages programmatically using the OSLog framework.
Topics
Essentials
Generating Log Messages from Your CodeViewing Log MessagesCustomizing Logging Behavior While Debugging