log
Logging as an effect, in pure Louise with no dependencies. An entry has a
level (Debug < Info < Warn < Error), a message and key=value fields.
Code logs through the log effect, and the handler the app installs
decides where entries go and which levels pass.
import log.{type log, Info}
fn deliver :: hook: Hook -> () / <log, io>
{
match sent hook
{ Ok(n) -> log.info "webhooks: delivered {n}" []
, Error(reason) -> log.warn "webhooks: failed" [("hook", hook.id), ("reason", reason)]
}
}
// In `main`: info and above, the level from LOG_LEVEL when it names one.
let least = os.env "LOG_LEVEL" |> option.then log.level_named |> option.unwrap_or Info
use <- log.to_console least
to_console writes one line per entry, stamped with time.now:
2026-11-05T14:02:11.734Z info webhooks: delivered 3
2026-11-05T14:02:12.250Z warn webhooks: failed hook=h-17 reason="connection refused"
Warn and Error go to stderr and the others to stdout. They share one
queue, so they keep their order (ADR 0022). A value that is empty or has
a space, ", =, a backslash or a newline is quoted with those escaped,
and a newline in a message is written \n, so an entry is always one line.
Handlers
to_console least: the lines above, for entries atleastor above.at_least least: drops the entries belowleastand passes the others to the enclosingloghandler, to quiet one part of an app.silently: drops every entry.captured: answers the action's result with the entries it logged, in order, for tests:let (_, entries) = log.captured fn { deliver hook } assert_equal entries [Entry(Info, "webhooks: delivered 1", [])]
line at entry is the text format on its own. The web package's
web/access logs one line per request through this effect.
Tests
louise test here, and louise test --native for the native backend.