moonlog — structured logging for MoonBit: six levels, fields carried as values rather than text, and a sink seam. No clock, no global state, no output of its own.
let log = @moonlog.Logger::new(@moonlog.Lines::new(line => println(line)))
log.info("listening", fields=[("port", Json::number(8000))])
log.warn("slow response", fields=[("path", Json::string("/report"))])
// INFO listening port=8000
// WARNING slow response path="/report"
// One JSON object per line, for a reader that is a machine.
@moonlog.Lines::new(line => println(line), format=@moonlog.json_line)
// {"level":"INFO","msg":"listening","port":8000}| Setting | Default | Why that one |
|---|---|---|
| level | Info | What every library here defaulted to, and what Python's logging, Go's slog and go-zero settle on |
| format on Lines | line | LEVEL message key=value, which is what a person reads. json_line is the one a machine reads |
| level_key / message_key | level / msg | What go-zero, zap and slog name them, so a line drops into a pipeline built for one of those. object(record, level~, message~) renames them for a pipeline that wants severity |
moon add moonbitstack/moonlogpub(all) struct Discard {
}let level_key : StringInstall
Download zipmoonlog — structured logging for MoonBit: six levels, fields carried as values rather than text, and a sink seam. No clock, no global state, no output of its own.