From f5f37cfb9caa81128c44cc7cd4836737e5f69392 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 11 Jun 2019 15:47:15 +0200 Subject: [PATCH] no parent id Signed-off-by: Yoshua Wuyts --- examples/trace.rs | 4 ++-- src/lib.rs | 7 +++++-- src/logger.rs | 16 ++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/trace.rs b/examples/trace.rs index df8f622..4ec4dc7 100644 --- a/examples/trace.rs +++ b/examples/trace.rs @@ -6,7 +6,7 @@ fn setup_logger() { .filter(None, log::LevelFilter::Trace) .build(); - async_log::Logger::wrap(logger, || (12, Some(13))) + async_log::Logger::wrap(logger, || 12) .start(log::LevelFilter::Trace) .unwrap(); } @@ -20,6 +20,6 @@ fn main() { span!("inner, x={}", x, { info!("we must go deeper {}", x); - }); + }) }) } diff --git a/src/lib.rs b/src/lib.rs index 8da0bab..eb05b66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,9 +77,12 @@ //! use log::info; //! //! fn setup_logger() { -//! env_logger::Builder::new() +//! let logger = env_logger::Builder::new() //! .filter(None, log::LevelFilter::Trace) -//! .try_init() +//! .build(); +//! +//! async_log::Logger::wrap(logger, || (12, Some(13))) +//! .start(log::LevelFilter::Trace) //! .unwrap(); //! } //! diff --git a/src/logger.rs b/src/logger.rs index e2ecb5f..9d7b575 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -7,7 +7,7 @@ use std::thread; #[derive(Debug)] pub struct Logger where - F: Fn() -> (u64, Option) + Send + Sync + 'static, + F: Fn() -> u64 + Send + Sync + 'static, { backtrace: bool, logger: L, @@ -16,7 +16,7 @@ where impl Logger where - F: Fn() -> (u64, Option) + Send + Sync + 'static, + F: Fn() -> u64 + Send + Sync + 'static, { /// Wrap an existing logger, extending it with async functionality. pub fn wrap(logger: L, with: F) -> Self { @@ -40,7 +40,7 @@ where } /// Call the `self.with` closure, and return its results. - fn with(&self) -> (u64, Option) { + fn with(&self) -> u64 { (self.with)() } @@ -62,7 +62,7 @@ fn thread_id() -> String { impl log::Log for Logger where - F: Fn() -> (u64, Option) + Send + Sync + 'static, + F: Fn() -> u64 + Send + Sync + 'static, { fn enabled(&self, metadata: &Metadata<'_>) -> bool { self.logger.enabled(metadata) @@ -70,15 +70,12 @@ where fn log(&self, record: &Record<'_>) { if self.enabled(record.metadata()) { - let (curr_id, parent_id) = self.with(); + let curr_id = self.with(); let depth = self.compute_stack_depth(&record); let symbol = async_log_capture_caller(depth); let thread_id = format!(", thread_id={}", thread_id()); let task_id = format!(", task_id={}", curr_id); - let parent_id = parent_id - .map(|pid| format!(", task_parent_id={}", pid)) - .unwrap_or_else(|| String::from("")); let (line, filename) = if self.backtrace { match symbol { @@ -107,12 +104,11 @@ where &log::Record::builder() .args(record.args().clone()) .args(format_args!( - "{}{}{}{}{}{}", + "{}{}{}{}{}", record.args(), filename, line, task_id, - parent_id, thread_id )) .metadata(record.metadata().clone())