OSLogRecorder
public struct OSLogRecorder: LogRecorder
The OSLogRecorder
is an implemention of the LogRecorder
protocol that
records log entries using the new unified logging system available
as of iOS 10.0, macOS 10.12, tvOS 10.0, and watchOS 3.0.
Unless a LogTypeTranslator
is specified during construction, the
OSLogRecorder
will record log messages with an OSLogType
of .default
.
This is consistent with the behavior of NSLog()
.
-
true
if theos_log()
function is available at runtime.Declaration
Swift
public static let isAvailable: Bool =
-
The
LogFormatter
s to be used in conjunction with the receiver.Declaration
Swift
public let formatters: [LogFormatter]
-
Governs how
OSLogType
values are generated fromLogEntry
values.Declaration
Swift
public let logTypeTranslator: OSLogTypeTranslator
-
The
OSLog
used to perform logging.Declaration
Swift
public let log: OSLog
-
The GCD queue used by the receiver to record messages.
Declaration
Swift
public let queue: DispatchQueue
-
Initialize an
OSLogRecorder
instance, which will record log entries using theos_log()
function.Important
os_log()
is only supported as of iOS 10.0, macOS 10.12, tvOS 10.0, and watchOS 3.0. On incompatible systems, this initializer will fail.Declaration
Swift
public init?(formatters: [LogFormatter], subsystem: String = "", logTypeTranslator: OSLogTypeTranslator = .default, queue: DispatchQueue? = nil)
Parameters
formatters
An array of
LogFormatter
s to use for formatting log entries to be recorded by the receiver. Each formatter is consulted in sequence, and the formatted string returned by the first formatter to yield a non-nil
value will be recorded (and subsequent formatters, if any, are skipped). The log entry is silently ignored and not recorded if every formatter returnsnil
.subsystem
The name of the subsystem performing the logging. Defaults to the empty string (
""
) if not specified.logTypeTranslator
An
OSLogTypeTranslator
value that governs howOSLogType
values are determined for log entries.queue
The
DispatchQueue
to use for the recorder. Ifnil
, a new queue will be created. -
Called to record the specified using the
os_log()
function.Note
This function is only called if one of the
formatters
associated with the receiver returned a non-nil
string for the givenLogEntry
.Declaration
Swift
public func record(message: String, for entry: LogEntry, currentQueue: DispatchQueue, synchronousMode: Bool)
Parameters
message
The message to record.
entry
The
LogEntry
for whichmessage
was created.currentQueue
The GCD queue on which the function is being executed.
synchronousMode
If
true
, the recording is being done in synchronous mode, and the recorder should act accordingly.