From 747d5a263b91c6ef26c5e596d4071a38ef32b5cc Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 23 Jun 2019 19:24:10 -0700 Subject: [PATCH] Colorful logging in examples --- interop/src/main.rs | 4 +++- quinn/examples/client.rs | 4 +++- quinn/examples/server.rs | 7 ++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/interop/src/main.rs b/interop/src/main.rs index 8ff46fd06..7533c5117 100644 --- a/interop/src/main.rs +++ b/interop/src/main.rs @@ -33,11 +33,13 @@ struct Opt { fn main() { let opt = Opt::from_args(); let code = { - let decorator = slog_term::PlainSyncDecorator::new(std::io::stderr()); + let decorator = slog_term::TermDecorator::new().stderr().build(); let drain = slog_term::FullFormat::new(decorator) .use_original_order() .build() .fuse(); + // We use a mutex-protected drain for simplicity; this tool is single-threaded anyway. + let drain = std::sync::Mutex::new(drain).fuse(); if let Err(e) = run(Logger::root(drain, o!()), opt) { eprintln!("ERROR: {}", e); 1 diff --git a/quinn/examples/client.rs b/quinn/examples/client.rs index 92ca93810..34145a11a 100644 --- a/quinn/examples/client.rs +++ b/quinn/examples/client.rs @@ -46,11 +46,13 @@ struct Opt { fn main() { let opt = Opt::from_args(); let code = { - let decorator = slog_term::PlainSyncDecorator::new(std::io::stderr()); + let decorator = slog_term::TermDecorator::new().stderr().build(); let drain = slog_term::FullFormat::new(decorator) .use_original_order() .build() .fuse(); + // We use a mutex-protected drain for simplicity; this example is single-threaded anyway. + let drain = std::sync::Mutex::new(drain).fuse(); if let Err(e) = run(Logger::root(drain, o!()), opt) { eprintln!("ERROR: {}", e); 1 diff --git a/quinn/examples/server.rs b/quinn/examples/server.rs index 02e45c3f1..e8f6e086d 100644 --- a/quinn/examples/server.rs +++ b/quinn/examples/server.rs @@ -69,11 +69,12 @@ struct Opt { fn main() { let opt = Opt::from_args(); let code = { - let decorator = slog_term::PlainSyncDecorator::new(std::io::stderr()); + let decorator = slog_term::TermDecorator::new().stderr().build(); let drain = slog_term::FullFormat::new(decorator) .use_original_order() - .build() - .fuse(); + .build(); + // We use a mutex-protected drain for simplicity; this example is single-threaded anyway. + let drain = std::sync::Mutex::new(drain).fuse(); if let Err(e) = run(Logger::root(drain, o!()), opt) { eprintln!("ERROR: {}", e.pretty()); 1