Customized Log Format Output In Rust With tracing
April 2024
Introduction
I'm working on the interface for Neopoligen. The end goal is to get really good error messages. At the start, I'm just trying to make them readable. This is the code I'm using to do that.
```cargo
tracing = "0.1"
tracing-subscriber = "0.3"
```
use ;
use fmt;
Output:
INFO This is an info message
DEBUG This is a debug message
Details
-
The code creates a custom tracing_subscriber formatter via
formatwith calls to customize the output -
Without applying the formatter, the output text would be:
2024-04-23T14:14:56.835109Z INFO _active_nvim_run: This is the log message -
.without_timeturns off the time stamp -
.with_targetturns off some diagnostic info about the function that's running the code -
The
.with_ansiline turns off formatting that adds colors for the terminal. Without it, you'd see something like:^[[32m INFO ^[[0m This is the log message
end of line