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 FileLogRecorder instance to use the given file path and log formatters. This will fail if filePath could not be opened for writing.

    Declaration

    Swift

    public init?(filePath: String, formatters: [LogFormatter])

    Parameters

    filePath

    The 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.

    formatters

    An 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-nil value will be recorded. If every formatter returns nil, the log entry is silently ignored and not recorded.

  • Called by the LogReceptacle to record the specified log message.

    Note

    This function is only called if one of the formatters associated with the receiver returned a non-nil string for the given LogEntry.

    Declaration

    Swift

    open override func record(message: String, for entry: LogEntry, currentQueue: DispatchQueue, synchronousMode: Bool)

    Parameters

    message

    The message to record.

    entry

    The LogEntry for which message 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.