trace: Add arguments struct to subscriber::Record (#955)

This branch changes the `Subscriber::record` method to take a new
arguments struct, `span::Record`. The `field::Record` trait was renamed
to `field::Visit` to prevent name conflicts.

In addition, the `ValueSet::is_empty`, `ValueSet::contains`, and
`ValueSet::record` methods were made crate-private, as they are exposed
on the `Attributes` and `Record` types. 

Signed-off-by: Eliza Weisman <[email protected]>
This commit is contained in:
Eliza Weisman
2019-03-07 12:41:10 -08:00
committed by GitHub
parent 6fbef0a528
commit d88aba8d1c
12 changed files with 186 additions and 143 deletions
@@ -15,7 +15,7 @@ extern crate humantime;
use self::ansi_term::{Color, Style};
use super::tokio_trace::{
self,
field::{Field, Record},
field::{Field, Visit},
Id, Level, Subscriber,
};
@@ -103,27 +103,23 @@ impl<'a> fmt::Display for ColorLevel<'a> {
}
impl Span {
fn new(
parent: Option<Id>,
_meta: &tokio_trace::Metadata,
values: &tokio_trace::field::ValueSet,
) -> Self {
fn new(parent: Option<Id>, attrs: &tokio_trace::span::Attributes) -> Self {
let mut span = Self {
parent,
kvs: Vec::new(),
};
values.record(&mut span);
attrs.record(&mut span);
span
}
}
impl Record for Span {
impl Visit for Span {
fn record_debug(&mut self, field: &Field, value: &fmt::Debug) {
self.kvs.push((field.name(), format!("{:?}", value)))
}
}
impl<'a> Record for Event<'a> {
impl<'a> Visit for Event<'a> {
fn record_debug(&mut self, field: &Field, value: &fmt::Debug) {
write!(
&mut self.stderr,
@@ -207,16 +203,14 @@ impl Subscriber for SloggishSubscriber {
}
fn new_span(&self, span: &tokio_trace::span::Attributes) -> tokio_trace::Id {
let meta = span.metadata();
let values = span.values();
let next = self.ids.fetch_add(1, Ordering::SeqCst) as u64;
let id = tokio_trace::Id::from_u64(next);
let span = Span::new(self.current.id(), meta, values);
let span = Span::new(self.current.id(), span);
self.spans.lock().unwrap().insert(id.clone(), span);
id
}
fn record(&self, span: &tokio_trace::Id, values: &tokio_trace::field::ValueSet) {
fn record(&self, span: &tokio_trace::Id, values: &tokio_trace::span::Record) {
let mut spans = self.spans.lock().expect("mutex poisoned!");
if let Some(span) = spans.get_mut(span) {
values.record(span);
@@ -271,12 +265,12 @@ impl Subscriber for SloggishSubscriber {
target = &event.metadata().target(),
)
.unwrap();
let mut recorder = Event {
let mut visitor = Event {
stderr,
comma: false,
};
event.record(&mut recorder);
write!(&mut recorder.stderr, "\n").unwrap();
event.record(&mut visitor);
write!(&mut visitor.stderr, "\n").unwrap();
}
#[inline]