Skip to main content

Logging & Debugging

The Foundation manager provides a customizable logger utility. The logger can be used in client application development, or it can be ignored.

The logging services are rendered as per contract with protocol Logger. The logging service uses Apple's Unified Logging System - OSLog as the underlying service provider. The logger service provides useful inline functions for each OSLogLevels in two flavours:

  • Log function accepting StaticString and Variadic CVarArg.
  • Log function accepting Any typed value.

Usage

We suggest you to create a OSLog instance providing subsytem and category, as per apple naming convention.

static let FLFoundationLog = FLFoundationFactory.logger(
subsystem: "com.quickplay.FLFoundation",
category: "HTTPClient")
FLFoundationLog.logDebug(...)
FLFoundationLog.logInfo(...)
FLFoundationLog.log(...)
FLFoundationLog.logError(...)
FLFoundationLog.logFault(...)

It is advised to provide subsystem value in reverse domain format. Easy way would be to get the bundle identifier of the framework or app in use. The category value must be a valid and thoughtful name of the module that is being logged. The logs can be viewed outside Xcode using Console.app and the subsystem and category values are used for filtering logs messages; makes debugging easier for developer.

alt-text It is advised to make your custom complex types conform to CustomDebugStringConvertible and CustomStringConvertible and make use of the wrapper functions passing your complex type to log them.

Privacy

The unified logging system considers dynamic strings and complex dynamic objects to be private, and does not collect them automatically. Considering this, the log messages needs to be marked with access modifiers. In situations where it is necessary to capture a dynamic string, you may explicitly declare the string public using the keyword public. For example, %{public}s.

The wrapper functions accepting Any type value as input with this logger service marks log message arguments as public with DEBUG and private with RELEASE configurations. It is up to the developer to mark arguments as public/private when using the other log function. Please beware of what you log, you don't wanna accidently expose confidential data i.e., secret key or anything of that sort.

Customize Log Output

To provide your own custom formatting while logging your custom type, extend it to conform to CustomOSLogMessageConvertible.