Logger

class Logger(source)

Logs for one tag. Obtain one from a LoggerFactory, or from KcoapLogging.logger for the global configuration.

Messages are lambdas, so nothing is formatted unless the level is enabled:

log.debug { "Retransmitting MID $mid, attempt $attempt" }
log.warn(error) { "Dropped a message from $peer" }

with returns a logger that adds fields to every record, which keeps per-exchange context out of the message text and easy to filter on.

Properties

Link copied to clipboard

The current configuration; re-read on every call so runtime changes apply immediately.

Link copied to clipboard
val tag: String

Functions

Link copied to clipboard
fun child(name: String): Logger

A logger for the sub-tag tag.name, keeping this logger's fields.

Link copied to clipboard
inline fun debug(error: Throwable? = null, message: () -> String)
Link copied to clipboard
inline fun error(error: Throwable? = null, message: () -> String)
Link copied to clipboard
inline fun info(error: Throwable? = null, message: () -> String)
Link copied to clipboard
Link copied to clipboard
fun payload(bytes: ByteArray): String

Renders message bytes for a log line: hex when LogConfig.payloadDumps is on, otherwise only the length. Never pass key material here.

Link copied to clipboard
inline fun trace(error: Throwable? = null, message: () -> String)
Link copied to clipboard
inline fun warn(error: Throwable? = null, message: () -> String)
Link copied to clipboard
fun with(vararg extra: Pair<String, Any?>): Logger

A logger with the same tag that adds extra to every record.