mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
1.5 KiB
1.5 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| json-console-sink | api | sink | 20260520 | Create the built-in JSON console sink for structured synchronous logging. |
|
Json-console-sink
Create the built-in JSON console sink. This sink writes records as structured JSON text and is useful when stdout is consumed by machines rather than humans.
Interface
pub fn json_console_sink() -> JsonConsoleSink {
output
JsonConsoleSink- Sink that writes records to the console as JSON.
Explanation
Detailed rules explaining key parameters and behaviors
- This sink emits JSON rather than human-focused text formatting.
- It is a direct synchronous sink that can be passed to
Logger::new(...). - Use it when structured logs should be parsed, shipped, or inspected programmatically.
How to Use
Here are some specific examples provided.
When Need Structured Stdout Logs
When log consumers expect machine-readable output:
let logger = Logger::new(json_console_sink(), target="api")
logger.info("ready", fields=[field("service", "bitlogger")])
In this example, the emitted console line is JSON-shaped.
Error Case
e.g.:
-
If human-focused text formatting is required, use a text console sink instead.
-
Console output still depends on the current runtime environment.
Notes
-
This sink is useful for structured stdout pipelines.
-
It pairs naturally with field-heavy logging.