RotatingLogFileRecorder
open class RotatingLogFileRecorder: LogRecorderBase
A LogRecorder implementation that maintains a set of daily rotating log
files, kept for a user-specified number of days.
Important
ARotatingLogFileRecorder instance assumes full control over
the log directory specified by its directoryPath property. Please see the
initializer documentation for details.
-
The number of days for which the receiver will retain log files before they’re eligible for pruning.
Declaration
Swift
open let daysToKeep: Int -
The filesystem path to a directory where the log files will be stored.
Declaration
Swift
open let directoryPath: String -
Initializes a new
RotatingLogFileRecorderinstance.Warning
The
RotatingLogFileRecorderexpects to have full control over the contents of itsdirectoryPath. Any file not recognized as an active log file will be deleted during the automatic pruning process, which may occur at any time. Therefore, be extremely careful when constructing the value passed in as thedirectoryPath.Declaration
Swift
public init(daysToKeep: Int, directoryPath: String, formatters: [LogFormatter] = [ReadableLogFormatter()])Parameters
daysToKeepThe number of days for which log files should be retained.
directoryPathThe filesystem path of the directory where the log files will be stored. Please note the warning above regarding the
directoryPath.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. -
Returns a string representing the filename that will be used to store logs recorded on the given date.
Declaration
Swift
open class func logFilename(forDate date: Date) -> StringParameters
dateThe
Datefor which the log file name is desired.Return Value
The filename.
-
Attempts to create—if it does not already exist—the directory indicated by the
directoryPathproperty.Throws
If the function fails to create a directory atdirectoryPath.Declaration
Swift
open func createLogDirectory() throws -
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. -
Deletes any expired log files (and any other detritus that may be hanging around inside our
directoryPath).Warning
Any file within thedirectoryPathnot recognized as an active log file will be deleted during pruning.Declaration
Swift
open func prune()
View on GitHub
RotatingLogFileRecorder Class Reference