Yet another structured logging library
4

Configure Feed

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

Gleam 83.1%
Erlang 9.9%
Nix 5.6%
Just 0.9%
Shell 0.5%
10 1 3

Clone this repository

https://tangled.org/ollie.earth/witness https://tangled.org/did:plc:osnsi4tzzvfco7mrsi6vrzxe
git@knot.ollie.earth:ollie.earth/witness git@knot.ollie.earth: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 logging
import witness

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

  // log a message
  witness.this(logging.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),
  ])
}

fn configure_logging() {
  // configure erlang logger
  logging.configure()

  // 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_short_string(level) <> " " <> message)
  })
  // log json to the erlang logger
  |> witness.with_sink(witness.Json, logging.log)
  // apply this config globally
  |> witness.set_config()
}

Will log this to the erlang logger:

INFO {"timestamp":"2026-05-28T18:30:40.020522296Z","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 to the console:

[INFO] 20:30:40 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://hexdocs.pm/witness.

Development#

gleam run   # Run the project
gleam test  # Run the tests