use owo_colors::{OwoColorize, Stream};
use std::fmt;
use tracing::field::Visit;
pub struct Visitor<'s, W: fmt::Write + Send> {
pub result: fmt::Result,
pub writer: &'s mut W,
pub stream: Stream,
pub colors: bool,
}
impl<W: fmt::Write + Send> Visit for Visitor<'_, W> {
fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn fmt::Debug) {
if self.result.is_err() {
return;
}
if field.name().starts_with("log.") {
return;
}
match field.name() {
"message" => {
self.result = write!(self.writer, "{value:?}");
}
name => {
let value = match self.colors {
true => format!("{name}={value:?}")
.if_supports_color(self.stream, |x| x.fg_rgb::<134, 134, 134>())
.to_string(),
false => format!("{name}={value:?}"),
};
self.result = write!(self.writer, " {value}");
}
}
}
}