Create JSON Log Files In Rust With tracing
This is what I'm using for my default logs to produce JSON output in Rust apps.
```cargo
= "0.1"
tracing-subscriber =
```
use ;
tracing
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()
rust
call, you have to add the "feature" in Cargo.toml
-- end of line --