RingBufferSink

class RingBufferSink(val capacity: Int) : LogSink(source)

Keeps the last capacity records in memory, so they can be gathered on demand: attached to a bug report, shown in a debug screen, or returned by a diagnostics endpoint.

Writing is lock free and never blocks the logging thread. When full, the oldest record is replaced.

val recent = RingBufferSink(capacity = 2_000)
KcoapLogging.configure { level = LogLevel.DEBUG; sink = ConsoleSink() + recent }
...
report.attach(recent.dump())

Constructors

Link copied to clipboard
constructor(capacity: Int)

Properties

Link copied to clipboard
Link copied to clipboard

How many records were overwritten because the buffer was full.

Functions

Link copied to clipboard

Passes on only records at level or above, for example to send warnings to a crash reporter.

Link copied to clipboard
fun clear()
Link copied to clipboard
fun dump(formatter: LogFormatter = LogFormatter.Default): String

The retained records as text, one per line, oldest first.

Link copied to clipboard
operator fun LogSink.plus(other: LogSink): LogSink

Sends each record to this sink and to other.

Link copied to clipboard

The retained records, oldest first.

Link copied to clipboard
open override fun write(record: LogRecord)