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
LogFormatters to be used in conjunction with the receiver.Declaration
Swift
public let formatters: [LogFormatter] -
Defines the interface of a function that translates
LogSeverityvalues intoASLPriorityLevelvalues. This function is used to determine theASLPriorityLevelused for a givenLogEntry.Declaration
Swift
public typealias LogLevelTranslator = (LogSeverity) -> ASLPriorityLevel -
The
ASLClientthat 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
LogLevelTranslatorfunction used by the receiver to convertLogSeverityvalues toASLPriorityLevelvalues. If one was not explicitly provided at instantiation, a default implementation will be used.Declaration
Swift
public let logLevelTranslator: LogLevelTranslator -
Initializes an
ASLLogRecorderinstance to use theDefaultLogFormatterimplementation for formatting log messages.Within ASL, log messages will be recorded at the
.warningpriority level, which is consistent with the behavior ofNSLog().Declaration
Swift
public init(echoToStdErr: Bool = true, addTraceAttributes: Bool = false)Parameters
echoToStdErrIf
true, ASL will also echo log messages to the calling process’sstderroutput stream.addTraceAttributesIf
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
ASLLogRecorderinstance to use the specifiedLogFormatterfor formatting log messages.Within ASL, log messages will be recorded at the
.warningpriority level, which is consistent with the behavior ofNSLog().Declaration
Swift
public init(formatter: LogFormatter, echoToStdErr: Bool = true, addTraceAttributes: Bool = false)Parameters
formatterA
LogFormatterto use for formatting log entries to be recorded by the receiver. If the formatter returnsnilfor a given log entry, it is silently ignored and not recorded.echoToStdErrIf
true, ASL will also echo log messages to the calling process’sstderroutput stream.addTraceAttributesIf
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
ASLLogRecorderinstance to use the specifiedLogFormatterfor formatting log messages.Within ASL, log messages will be recorded at the
.warningpriority level, which is consistent with the behavior ofNSLog().Declaration
Swift
public init(formatters: [LogFormatter], echoToStdErr: Bool = true, addTraceAttributes: Bool = false)Parameters
formattersAn array of
LogFormatters 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-nilvalue will be recorded. If every formatter returnsnil, the log entry is silently ignored and not recorded.echoToStdErrIf
true, ASL will also echo log messages to thestderroutput stream of the running process.addTraceAttributesIf
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
ASLLogRecorderinstance to use the specifiedLogFormatterfor formatting log entries.Declaration
Swift
public init(logLevelTranslator translator: @escaping LogLevelTranslator, formatters: [LogFormatter], echoToStdErr: Bool = true, addTraceAttributes: Bool = false)Parameters
translatorA
LogLevelTranslatorfunction that is used to convertLogSeverityvalues toASLPriorityLevelvalues.formattersAn array of
LogFormatters 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-nilvalue will be recorded. If every formatter returnsnil, the log entry is silently ignored and not recorded.echoToStdErrIf
true, ASL will also echo log messages to the calling process’sstderroutput stream.addTraceAttributesIf
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
formattersassociated with the receiver returned a non-nilstring for the givenLogEntry.Declaration
Swift
public func record(message: String, for entry: LogEntry, currentQueue: DispatchQueue, synchronousMode: Bool)Parameters
messageThe message to record.
entryThe
LogEntryfor whichmessagewas created.currentQueueThe GCD queue on which the function is being executed.
synchronousModeIf
true, the receiver should record the log entry synchronously and flush any buffers before returning.
View on GitHub
ASLLogRecorder Struct Reference