Skip to content

Releases: sambyeol/scribe

v0.1.0

02 Jun 08:00
b3991db

Choose a tag to compare

First public release of scribe, a value-based structured logging library for OCaml. A logger is an ordinary value that carries its level, sink, and context fields, so application code can compose loggers and library code can accept ?logger without touching process-wide logging state.

Highlights

  • Value-based loggersScribe.create ~level ~sink, extended with Scribe.with_field / Scribe.with_fields; compose and pass loggers as plain values.
  • Levels & filteringApp, Error, Warning, Info, Debug, with per-logger level filtering. Emit via log or the app / error / warn / info / debug helpers.
  • Structured fields — typed string / int / bool fields; logger context fields merge with call-site fields, with call-site values winning on key collisions.
  • Sink abstraction — build custom sinks with Sink.make; Scribe.noop is a library-friendly default for ?logger.
  • scribe.sinks — a JSON-lines sink (Scribe_sinks.Json, one object per line via yojson) and a noop sink (Scribe_sinks.Noop).

Example

let logger =
  Scribe.create
    ~level:Scribe.Level.Warning
    ~sink:(Scribe_sinks.Json.stderr ())
  |> Scribe.with_field (Scribe.Field.string "component" "mir.parser")

let () =
  Scribe.warn logger "metadata parse failed"
    [ Scribe.Field.string "reason" "malformed directive" ]
{"level":"warning","message":"metadata parse failed","fields":{"component":"mir.parser","reason":"malformed directive"}}

Installation

scribe is distributed through Git tags; pin it with opam:

opam pin add scribe "https://github.com/sambyeol/scribe.git#v0.1.0"

Then depend on the libraries from your dune file:

(libraries scribe scribe.sinks)

Requirements

  • OCaml >= 4.14
  • dune >= 3.23