Files
Nanaloveyuki 0b05ee0c94 πŸ”– release 0.7.3
2026-07-19 17:12:02 +08:00

1.5 KiB

Console And Structured Fields

Use this flow for command-line tools and services that need a human-readable starting point. A record always has a level, target, message, and optional fields.

Install And Import

moon add Nanaloveyuki/BitLogger@0.7.3
import {
  "Nanaloveyuki/BitLogger/src" @log,
}

Build A Console Logger

fn main {
  let logger = @log.build_logger(
    @log.console(min_level=@log.Level::Info, target="service.http"),
  )

  logger.info("listening", fields=[
    @log.field("port", "8080"),
    @log.field("environment", "development"),
  ])
  logger.warn("slow request", fields=[@log.field("path", "/health")])
}

min_level filters records before they reach the sink. target identifies the subsystem, while fields carry queryable context without interpolating it into the message.

Switch To JSON

Keep the logging calls unchanged and replace the preset:

let logger = @log.build_logger(
  @log.json_console(min_level=@log.Level::Info, target="service.http"),
)

This is the preferred output for a collector that consumes one structured record per line.

Next Steps