Yet another structured logging library
0

Configure Feed

Select the types of activity you want to include in your feed.

Gleam 77.1%
Shell 9.6%
Erlang 8.1%
Nix 3.3%
JavaScript 1.4%
Just 0.4%
13 2 4

Clone this repository

https://git.vm.fail/ollie.earth/witness https://git.vm.fail/did:plc:osnsi4tzzvfco7mrsi6vrzxe
ssh://git@knot.ollie.earth:2222/ollie.earth/witness ssh://git@knot.ollie.earth:2222/did:plc:osnsi4tzzvfco7mrsi6vrzxe

For self-hosted knots, clone URLs may differ based on your setup.


README.md

witness#

Package Version Hex Docs

gleam add witness@1 logging@1
import gleam/io
import witness

pub fn main() -> Nil {
  configure_logging()

  // log a message
  witness.this(witness.Info, "Some log message", [
    witness.string("example", "you can add structured data"),
    witness.bool("also_bools", True),
    witness.float("and_floats", 1.23),
    witness.int("ints_as_well", 3),
  ])
}

/// Configure the logging. (Only needs to be run once at startup)
///
fn configure_logging() {
  // create a new config
  witness.empty_config()
  // log formatted text to stdout
  |> witness.with_sink(witness.Text, fn(level, message) {
    io.println(witness.level_to_badge(level) <> ": " <> message)
  })
  // log as json 
  |> witness.with_sink(witness.Json, fn(_, message) {
    // ideally you'd log this to a file using, for example, the erlang logger
    io.println(message)
  })
  // apply this config globally
  |> witness.set_config()
}

Will log this json line:

{"timestamp":"2026-07-22T17:13:17.100815963Z","level":"info","message":"Some log message","example":"you can add structured data","also_bools":true,"and_floats":1.23,"ints_as_well":3}

And this text to the console:

[INFO]: 19:13:17 Some log message
  example: you can add structured data
  also_bools: True
  and_floats: 1.23
  ints_as_well: 3

Further documentation can be found at https://witness.hexdocs.pm.