witness
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