Json-console
Create a LoggerConfig preset for structured JSON output on the console. This preset is intended for config-driven logging pipelines that want machine-readable terminal output.
Interface
pub fn json_console(
min_level~ : Level = Level::Info,
target~ : String = "",
timestamp~ : Bool = false,
) -> LoggerConfig {input
min_level : Level- Minimum enabled level for the preset.target : String- Default target stored in the returned config.timestamp : Bool- Whether emitted records should include timestamps.
output
LoggerConfig- Config usingSinkKind::JsonConsolewith no queue wrapper by default.
Explanation
Detailed rules explaining key parameters and behaviors
- This preset always returns
sink.kind=SinkKind::JsonConsole. queue=Noneby default, so JSON records are not buffered unlesswith_queue(...)is added later.- The preset does not carry file-only fields such as
pathorrotationin a meaningful way because the sink kind is not file-based.
How to Use
Here are some specific examples provided.
When Need Structured Console Output
When logs should be easy to collect or parse from stdout:
let config = json_console(min_level=Level::Info, target="api", timestamp=true)
let logger = build_logger(config)In this example, records are emitted through the JSON console sink.
And timestamps are enabled at the top-level logger config.
Error Case
e.g.:
If
targetis empty, the preset still returns a valid config.If you need file rotation or file paths, this preset is the wrong sink shape and should be replaced with
file(...).
Notes
Use this preset when downstream tooling expects structured console logs.
with_file_rotation(...)does not change this preset because it only applies to file configs.