OSLogEventSink

public class OSLogEventSink : EventSink

An EventSink for logging events to the Apple unified logging system.

This is the default event sink, but you can and should create one yourself to specify the subsystem and category to use when logging your events. This will make it easier to query for your app’s events, which can help filter out log noise.

Remark

os_log is not actually a particularly good destination for structured, high-cardinality events. The unified logging system doesn’t have any understanding of the structure, so you can’t do sophisticated queries against your fields, and we have to circumvent the privacy protections that the system has for dynamic values, since we render the entire log string dynamically. The main thing os_log has going for it is that it is easily available since it is the default logging system for Apple’s platforms.
  • Create a new os_log sink, optionally targeting a particular log.

    Declaration

    Swift

    public init(log: OSLog = .default)

    Parameters

    log

    The log to send events to.

  • Create a new os_log sink for a particular subsystem and category.

    This is a shortcut, and is no different than using init(log:) and providing an OSLog with the given subsystem and category.

    Declaration

    Swift

    public convenience init(subsystem: String, category: String)

    Parameters

    subsystem

    The subsystem to log events to. This is generally structured as a reverse-DNS name, like com.myapp.App. If you’re unsure what it should be, use your app’s bundle identifier.

    category

    The category to log events to. This is an arbitrary label within your subsystem, and can be used with configuration profiles to control logging policy in the unified logging system. If you’re unsure what it should be, use "events".

  • Declaration

    Swift

    public func send(event: Event, level: OSLogType)