ASLLogRecorder
public struct ASLLogRecorder: LogRecorder
The ASLLogRecorder
is an implemention of the LogRecorder
protocol that
records log entries to the Apple System Log (ASL) facility.
Unless a LogLevelTranslator
is specified during construction, the
ASLLogRecorder
will record log messages using ASL_LEVEL_WARNING
. This
is consistent with the behavior of NSLog()
.
-
The
LogFormatter
s to be used in conjunction with the receiver.Declaration
Swift
public let formatters: [LogFormatter]
-
Defines the interface of a function that translates
LogSeverity
values intoASLPriorityLevel
values. This function is used to determine theASLPriorityLevel
used for a givenLogEntry
.Declaration
Swift
public typealias LogLevelTranslator = (LogSeverity) -> ASLPriorityLevel
-
The
ASLClient
that will be used to perform logging.Declaration
Swift
public let client: ASLClient
-
The GCD queue used by the receiver to record messages.
Declaration
Swift
public var queue: DispatchQueue
-
The
LogLevelTranslator
function used by the receiver to convertLogSeverity
values toASLPriorityLevel
values. If one was not explicitly provided at instantiation, a default implementation will be used.Declaration
Swift
public let logLevelTranslator: LogLevelTranslator
-
Initializes an
ASLLogRecorder
instance to use theDefaultLogFormatter
implementation for formatting log messages.Within ASL, log messages will be recorded at the
.warning
priority level, which is consistent with the behavior ofNSLog()
.Declaration
Swift
public init(echoToStdErr: Bool = true, addTraceAttributes: Bool = false)
Parameters
echoToStdErr
If
true
, ASL will also echo log messages to the calling process’sstderr
output stream.addTraceAttributes
If
true
, additional program trace attributes will be included in each message logged to ASL. This will include the filesystem path of the source code file, the source code line of the call site, and the stack frame representing the caller. You probably don’t want this included in production code. -
Initializes an
ASLLogRecorder
instance to use the specifiedLogFormatter
for formatting log messages.Within ASL, log messages will be recorded at the
.warning
priority level, which is consistent with the behavior ofNSLog()
.Declaration
Swift
public init(formatter: LogFormatter, echoToStdErr: Bool = true, addTraceAttributes: Bool = false)
Parameters
formatter
A
LogFormatter
to use for formatting log entries to be recorded by the receiver. If the formatter returnsnil
for a given log entry, it is silently ignored and not recorded.echoToStdErr
If
true
, ASL will also echo log messages to the calling process’sstderr
output stream.addTraceAttributes
If
true
, additional program trace attributes will be included in each message logged to ASL. This will include the filesystem path of the source code file, the source code line of the call site, and the stack frame representing the caller. You probably don’t want this included in production code. -
Initializes an
ASLLogRecorder
instance to use the specifiedLogFormatter
for formatting log messages.Within ASL, log messages will be recorded at the
.warning
priority level, which is consistent with the behavior ofNSLog()
.Declaration
Swift
public init(formatters: [LogFormatter], echoToStdErr: Bool = true, addTraceAttributes: Bool = false)
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. If every formatter returnsnil
, the log entry is silently ignored and not recorded.echoToStdErr
If
true
, ASL will also echo log messages to thestderr
output stream of the running process.addTraceAttributes
If
true
, additional program trace attributes will be included in each message logged to ASL. This will include the filesystem path of the source code file, the source code line of the call site, and the stack frame representing the caller. You probably don’t want this included in production code. -
Initializes a new
ASLLogRecorder
instance to use the specifiedLogFormatter
for formatting log entries.Declaration
Swift
public init(logLevelTranslator translator: @escaping LogLevelTranslator, formatters: [LogFormatter], echoToStdErr: Bool = true, addTraceAttributes: Bool = false)
Parameters
translator
A
LogLevelTranslator
function that is used to convertLogSeverity
values toASLPriorityLevel
values.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. If every formatter returnsnil
, the log entry is silently ignored and not recorded.echoToStdErr
If
true
, ASL will also echo log messages to the calling process’sstderr
output stream.addTraceAttributes
If
true
, additional program trace attributes will be included in each message logged to ASL. This will include the filesystem path of the source code file, the source code line of the call site, and the stack frame representing the caller. You probably don’t want this included in production code. -
Called to record the specified message to the Apple System Log.
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 receiver should record the log entry synchronously and flush any buffers before returning.