Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscriber: add lifetime parameter to MakeWriter #781

Merged
merged 6 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tracing-appender/src/non_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ impl std::io::Write for NonBlocking {
}
}

impl MakeWriter for NonBlocking {
impl<'a> MakeWriter<'a> for NonBlocking {
type Writer = NonBlocking;

fn make_writer(&self) -> Self::Writer {
fn make_writer(&'a self) -> Self::Writer {
self.clone()
}
}
Expand Down
2 changes: 1 addition & 1 deletion tracing-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ traced-error = []

[dependencies]
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", default-features = false, features = ["registry", "fmt"] }
tracing = { path = "../tracing", version = "0.2"}
tracing = { path = "../tracing", version = "0.2" }

[badges]
maintenance = { status = "experimental" }
Expand Down
62 changes: 20 additions & 42 deletions tracing-subscriber/src/fmt/fmt_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<S, N, E, W> Subscriber<S, N, E, W>
where
S: Collect + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
W: MakeWriter + 'static,
W: for<'writer> MakeWriter<'writer> + 'static,
{
/// Sets the [event formatter][`FormatEvent`] that the layer will use to
/// format events.
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<S, N, E, W> Subscriber<S, N, E, W> {
/// [`Subscriber`]: ../layer/trait.Subscriber.html
pub fn with_writer<W2>(self, make_writer: W2) -> Subscriber<S, N, E, W2>
where
W2: MakeWriter + 'static,
W2: for<'writer> MakeWriter<'writer> + 'static,
{
Subscriber {
fmt_fields: self.fmt_fields,
Expand Down Expand Up @@ -473,7 +473,7 @@ where
S: Collect + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<S, N> + 'static,
W: MakeWriter + 'static,
W: for<'writer> MakeWriter<'writer> + 'static,
{
#[inline]
fn make_ctx<'a>(&'a self, ctx: Context<'a, S>) -> FmtContext<'a, S, N> {
Expand Down Expand Up @@ -554,7 +554,7 @@ where
S: Collect + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<S, N> + 'static,
W: MakeWriter + 'static,
W: for<'writer> MakeWriter<'writer> + 'static,
{
fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
let span = ctx.span(id).expect("Span not found, this is a bug");
Expand Down Expand Up @@ -859,14 +859,12 @@ mod test {
self,
format::{self, test::MockTime, Format},
subscribe::Subscribe as _,
test::MockWriter,
test::MockMakeWriter,
time,
};
use crate::Registry;
use format::FmtSpan;
use lazy_static::lazy_static;
use regex::Regex;
use std::sync::Mutex;
use tracing::collect::with_default;
use tracing_core::dispatch::Dispatch;

Expand Down Expand Up @@ -925,13 +923,9 @@ mod test {

#[test]
fn synthesize_span_none() {
lazy_static! {
static ref BUF: Mutex<Vec<u8>> = Mutex::new(vec![]);
}

let make_writer = || MockWriter::new(&BUF);
let make_writer = MockMakeWriter::default();
let subscriber = crate::fmt::Collector::builder()
.with_writer(make_writer)
.with_writer(make_writer.clone())
.with_level(false)
.with_ansi(false)
.with_timer(MockTime)
Expand All @@ -942,19 +936,15 @@ mod test {
let span1 = tracing::info_span!("span1", x = 42);
let _e = span1.enter();
});
let actual = sanitize_timings(String::from_utf8(BUF.try_lock().unwrap().to_vec()).unwrap());
let actual = sanitize_timings(make_writer.get_string());
assert_eq!("", actual.as_str());
}

#[test]
fn synthesize_span_active() {
lazy_static! {
static ref BUF: Mutex<Vec<u8>> = Mutex::new(vec![]);
}

let make_writer = || MockWriter::new(&BUF);
let make_writer = MockMakeWriter::default();
let subscriber = crate::fmt::Collector::builder()
.with_writer(make_writer)
.with_writer(make_writer.clone())
.with_level(false)
.with_ansi(false)
.with_timer(MockTime)
Expand All @@ -965,7 +955,7 @@ mod test {
let span1 = tracing::info_span!("span1", x = 42);
let _e = span1.enter();
});
let actual = sanitize_timings(String::from_utf8(BUF.try_lock().unwrap().to_vec()).unwrap());
let actual = sanitize_timings(make_writer.get_string());
assert_eq!(
"fake time span1{x=42}: tracing_subscriber::fmt::fmt_subscriber::test: enter\n\
fake time span1{x=42}: tracing_subscriber::fmt::fmt_subscriber::test: exit\n",
Expand All @@ -975,13 +965,9 @@ mod test {

#[test]
fn synthesize_span_close() {
lazy_static! {
static ref BUF: Mutex<Vec<u8>> = Mutex::new(vec![]);
}

let make_writer = || MockWriter::new(&BUF);
let make_writer = MockMakeWriter::default();
let subscriber = crate::fmt::Collector::builder()
.with_writer(make_writer)
.with_writer(make_writer.clone())
.with_level(false)
.with_ansi(false)
.with_timer(MockTime)
Expand All @@ -992,7 +978,7 @@ mod test {
let span1 = tracing::info_span!("span1", x = 42);
let _e = span1.enter();
});
let actual = sanitize_timings(String::from_utf8(BUF.try_lock().unwrap().to_vec()).unwrap());
let actual = sanitize_timings(make_writer.get_string());
assert_eq!(
"fake time span1{x=42}: tracing_subscriber::fmt::fmt_subscriber::test: close timing timing\n",
actual.as_str()
Expand All @@ -1001,13 +987,9 @@ mod test {

#[test]
fn synthesize_span_close_no_timing() {
lazy_static! {
static ref BUF: Mutex<Vec<u8>> = Mutex::new(vec![]);
}

let make_writer = || MockWriter::new(&BUF);
let make_writer = MockMakeWriter::default();
let subscriber = crate::fmt::Collector::builder()
.with_writer(make_writer)
.with_writer(make_writer.clone())
.with_level(false)
.with_ansi(false)
.with_timer(MockTime)
Expand All @@ -1019,7 +1001,7 @@ mod test {
let span1 = tracing::info_span!("span1", x = 42);
let _e = span1.enter();
});
let actual = sanitize_timings(String::from_utf8(BUF.try_lock().unwrap().to_vec()).unwrap());
let actual = sanitize_timings(make_writer.get_string());
assert_eq!(
" span1{x=42}: tracing_subscriber::fmt::fmt_subscriber::test: close\n",
actual.as_str()
Expand All @@ -1028,13 +1010,9 @@ mod test {

#[test]
fn synthesize_span_full() {
lazy_static! {
static ref BUF: Mutex<Vec<u8>> = Mutex::new(vec![]);
}

let make_writer = || MockWriter::new(&BUF);
let make_writer = MockMakeWriter::default();
let subscriber = crate::fmt::Collector::builder()
.with_writer(make_writer)
.with_writer(make_writer.clone())
.with_level(false)
.with_ansi(false)
.with_timer(MockTime)
Expand All @@ -1045,7 +1023,7 @@ mod test {
let span1 = tracing::info_span!("span1", x = 42);
let _e = span1.enter();
});
let actual = sanitize_timings(String::from_utf8(BUF.try_lock().unwrap().to_vec()).unwrap());
let actual = sanitize_timings(make_writer.get_string());
assert_eq!(
"fake time span1{x=42}: tracing_subscriber::fmt::fmt_subscriber::test: new\n\
fake time span1{x=42}: tracing_subscriber::fmt::fmt_subscriber::test: enter\n\
Expand Down
Loading