Skip to content

rafambn/Scribe

Repository files navigation

Scribe

A flavored Kotlin Multiplatform logging library

Scribe logo

Maven Central License Platform Targets

Scribe is a Kotlin Multiplatform logging library built around the ideas from loggingsucks.com, so structured logs can model both single events and longer contextual flows.

Documentation Page

Features:

  • Story-driven logging primitives instead of flat logger calls
  • Single-event logging with note(...) and contextual logging with newScroll(...)
  • Delivery hooks through NoteSaver, ScrollSaver, and EntrySaver
  • Scroll lifecycle enrichment through Margin

Setup

Add Scribe to your commonMain dependencies:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("com.rafambn:scribe:0.2.3")
        }
    }
}

Usage

Initialize Scribe, hire the runtime, and emit a note:

Scribe.inscribe {
    shelves = listOf(
        NoteSaver { note ->
            println("[${note.level}] ${note.tag}: ${note.message}")
        }
    )
}
Scribe.hire(channel = Channel(capacity = 256))

Scribe.note(
    tag = "payments",
    message = "starting checkout",
    level = Urgency.INFO,
)

Use a scroll when you need shared context for a longer flow:

Scribe.inscribe {
    shelves = listOf(
        ScrollSaver { scroll -> println(scroll) }
    )
    imprint = mapOf(
        "service" to JsonPrimitive("billing"),
        "environment" to JsonPrimitive("production"),
    )
}
Scribe.hire(channel = Channel(capacity = 256))

val scroll = Scribe.newScroll(id = "checkout-42")
scroll["gateway"] = JsonPrimitive("stripe")
scroll["attempt"] = JsonPrimitive(1)
scroll["retry"] = JsonPrimitive(false)
scroll.seal(success = true)

Each seal(...) call emits a separate SealedScroll snapshot, so sealing the same scroll more than once is allowed when you need multiple terminal records.

Choose the saver that matches your output flow:

val noteSaver = NoteSaver { note -> println(note) }
val scrollSaver = ScrollSaver { scroll -> println(scroll) }
val entrySaver = EntrySaver { record -> println(record) }

About

Simple Logging Lib for KMP based on the concepts of loggingsucks.com

Topics

Resources

License

Stars

Watchers

Forks

Contributors