open class BufferedLogRecorder<BufferItem>: LogRecorderBase
BufferedLogRecorder is a generic
LogRecorder that buffers the log
messages passed to its
Construction requires a
createBufferItem function, which is responsible
for converting the
LogEntry and formatted message
String into the
Three specific subclasses are also provided which will buffer a different
BufferItem type for each call to
The maximum number if items that will be stored in the receiver’s buffer
open let bufferLimit: Int
The buffer, an array of
BufferItems created to represent the
LogEntryvalues recorded by the receiver.
open private(set) var buffer: [BufferItem]
Initializes a new
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-
nilvalue will be recorded. If every formatter returns
nil, the log entry is silently ignored and not recorded.
If this value is positive, it specifies the maximum number of items to store in the buffer. If
record()is called when the buffer limit has been reached, the oldest item in the buffer will be dropped. If this value is zero or negative, no limit will be applied. Note that this is potentially dangerous in production code, since memory consumption will grow endlessly unless you manually clear the buffer periodically.
DispatchQueueto use for the recorder. If
nil, a new queue will be created.
The function used to create
BufferIteminstances for each
LogEntryand formatted message string passed to the receiver’s
Called by the
LogReceptacleto record the formatted log message.
This function is only called if one of the
formattersassociated with the receiver returned a non-
nilstring for the given
open override func record(message: String, for entry: LogEntry, currentQueue: DispatchQueue, synchronousMode: Bool)
The message to record.
The GCD queue on which the function is being executed.
true, the recording is being done in synchronous mode, and the recorder should act accordingly.
Clears the contents of the buffer.
This operation is performed synchronously on the receiver’s
queueto ensure thread safety.
public func clear()