StructuredTimber

Entry point for structured logging.

Wraps Timber to pass key-value fields alongside log messages. Fields are stored in a ThreadLocal and consumed by StructuredTree. Each thread maintains its own pending fields, so this object is safe to use from multiple threads concurrently without synchronization.

Call init to set up structured logging before using any logging methods:

StructuredTimber.init(
LogcatSink(minPriority = Log.DEBUG),
globalFields = mapOf("app_version" to BuildConfig.VERSION_NAME),
)

Then log messages with structured fields:

StructuredTimber.d("Purchase completed",
"item_id" to "SKU-123",
"price" to 1980,
"currency" to "JPY"
)

Alternatively, you can plant a StructuredTree manually via Timber.plant for advanced use cases.

Since

1.0.0

Types

Link copied to clipboard
class Tagged

A structured logger that prefixes every log call with a fixed tag.

Functions

Link copied to clipboard
fun d(message: String, vararg fields: Pair<String, Any?>)

Log a structured message at DEBUG level.

Link copied to clipboard
fun e(message: String, vararg fields: Pair<String, Any?>)

Log a structured message at ERROR level.

fun e(t: Throwable, message: String, vararg fields: Pair<String, Any?>)

Log a structured message at ERROR level with a Throwable.

Link copied to clipboard
fun i(message: String, vararg fields: Pair<String, Any?>)

Log a structured message at INFO level.

Link copied to clipboard
fun init(vararg sinks: Sink, globalFields: Map<String, Any?> = emptyMap())

Initialize structured logging by planting a StructuredTree with the given sinks.

Link copied to clipboard

Return a Tagged builder for the given tag.

Link copied to clipboard
fun v(message: String, vararg fields: Pair<String, Any?>)

Log a structured message at VERBOSE level.

Link copied to clipboard
fun w(message: String, vararg fields: Pair<String, Any?>)

Log a structured message at WARN level.

Link copied to clipboard
fun wtf(message: String, vararg fields: Pair<String, Any?>)

Log a structured message at WTF level.