In Swift, an overview of Apple’s unified registration system

In Swift, an overview of Apple's unified registration system

For example, [a bug] might occur only after a few days of app usage. In this case, running an app in a simulator and testing a feature doesn’t make sense. We need to understand what the user has done in the application and how it responds to user actions in this situation. In his articles, Jabrayilov describes a technique leveraging Apple’s Unified Logging System to make it as easy as it goes to build a proper logging system into an iOS app.

Majid Jabrayilov, an iOS independent developer, recently published a series of essays emphasising the necessity of logging for analysing errors that are difficult to discover in the debugger as well as better understanding user behaviour in the app. While utilising the Xcode debugger to test an iOS app is a smart way to verify that it is bug-free, there are times when this is simply not an option, according to Jabrayilov.

Highlights

  • An interesting feature of Apple’s Unified Logging System is it makes it easy to export log information from a user’s device, which can become a life-saver in case a bug only shows up in the field and is not reproducible during testing. To this aim, you define a custom OSLogStore that is responsible for filtering all log entries matching specific criteria, including the entry category, date, and so on. As Jabrayilov shows, OSLogStore can be easily integrated in your app to allow the user to export log entries by tapping a button and optionally share them with the developer.

  • The cornerstone of this approach is the os.Logger class, which persists all log entries to a device-based system store under a given subsystem and category. Logger provides several levels of logging, including trace, notice, warning, and critical. Log entries are accessible through the Console.app on your Mac. To make all logged information easily readable in Console.app, Jabrayilov says it is convenient to use the OSLogInterpolation policies that are available beginning iOS 14. Those include options to control alignment, visibility, format, etc.

Overall, Jabrayilov describes a convenient technique to add logging to any iOS app. If you are interested, do not miss the original articles, which include sample code to illustrate all these concepts in detail.