Files
2026-07-17 16:24:06 +08:00

1.3 KiB

Configuration-Driven Logging

Use configuration when deployment should select levels, output, formatting, or queue behavior without changing application code.

Parse, Build, Then Log

let raw = "{\"min_level\":\"info\",\"target\":\"service\",\"sink\":{\"kind\":\"text_console\",\"text_formatter\":{\"show_timestamp\":false,\"separator\":\" | \"}},\"queue\":{\"max_pending\":64,\"overflow\":\"DropOldest\"}}"

let config = @log.parse_logger_config_text(raw) catch {
  err => {
    ignore(err)
    println("invalid logger configuration")
    return
  }
}

let logger = @log.build_logger(config)
logger.info("configured logger ready")
ignore(logger.flush())

Parsing validates the data before runtime construction. Keep the raw configuration outside application code in a real deployment, but handle parsing errors at the boundary where configuration enters the process.

Run The Repository Example

moon run examples/config_build

Next Steps