mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-23 16:32:19 +00:00
1.5 KiB
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
- Use Text formatting for a custom terminal format.
- Use Configuration when levels, targets, and sinks come from JSON.
- Reference:
console(...),json_console(...),field(...), andbuild_logger(...).