FileLogRecorder
open class FileLogRecorder: LogRecorderBase
A LogRecorder implementation that appends log entries to a file.
Note
FileLogRecorder is a simple log appender that provides no mechanism
for file rotation or truncation. Unless you manually manage the log file when
a FileLogRecorder doesn’t have it open, you will end up with an ever-growing
file. Use a RotatingLogFileRecorder instead if you’d rather not have to
concern yourself with such details.
-
The path of the file to which log entries will be written.
Declaration
Swift
open let filePath: String -
Attempts to initialize a new
FileLogRecorderinstance to use the given file path and log formatters. This will fail iffilePathcould not be opened for writing.Declaration
Swift
public init?(filePath: String, formatters: [LogFormatter])Parameters
filePathThe path of the file to be written. The containing directory must exist and be writable by the process. If the file does not yet exist, it will be created; if it does exist, new log messages will be appended to the end of the file.
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. -
Called by the
LogReceptacleto record the specified log message.Note
This function is only called if one of the
formattersassociated with the receiver returned a non-nilstring for the givenLogEntry.Declaration
Swift
open override 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 recording is being done in synchronous mode, and the recorder should act accordingly.
View on GitHub
FileLogRecorder Class Reference