Create JSON Log Files In Rust With tracing
April 2024
This is what I'm using for my default logs to produce JSON output in Rust apps.
```cargo
tracing = "0.1"
tracing-subscriber =
```
use ;
Output:
{"timestamp":"2024-04-23T14:42:04.834323Z","level":"INFO","fields":{"message":"This is the log message"},"target":"_active_nvim_run"}
{"timestamp":"2024-04-23T14:42:04.834498Z","level":"DEBUG","fields":{"message":"This is a debug message"},"target":"_active_nvim_run"}
Details
-
The biggest thing to note is that in order to use the `.json()
rustcall, you have to add the "feature" in Cargo.toml
end of line