Log

object Log

The Log component provides a simple logging API.

Usually, the log Emitter and Sink are separate units.

Library Guide (Log Producers)

Library modules define Categorys to distinguish the types of logs they emit, and produce logs using the Emitter or IdentifiableEmitter interfaces.

Example

enum class LibraryComponent : Log.Category {
A, B
}

class Manager: Log.Emitter {
var logger: Log.Sink<LibraryComponent>? = Log.Sink.Null

fun event() {
logger?.i(LibraryComponent.A) { "Some event" }
}
}

Application Guide (Log Consumers)

Applications consume logs by implementing or using one of the Sink implementations.

Example

val m = Manager()
m.logger = Log.Sink.Default { category, level ->
level >= Log.Level.DEBUG
}

See also

Types

Link copied to clipboard
interface Category

A typed label identifying the layer or component that produced a log entry.

Link copied to clipboard
interface Emitter

An instance of this interface can produce logs.

Link copied to clipboard
class Event<C : Log.Category>(val category: C, val level: Log.Level, val source: String?, messageBuilder: () -> String)

A log event.

Link copied to clipboard

This interface should be implemented by an identifiable object that can produce logs.

Link copied to clipboard

Severity of a log entry.

Link copied to clipboard
interface SharedLogFlow<C : Log.Category> : SharedFlow<Log.Event<C>> , Log.Sink<C>

A shared flow of log events, which can be assigned as a Sink.

Link copied to clipboard
fun interface Sink<in C : Log.Category>

Sink for log entries.