diff --git a/Cargo.lock b/Cargo.lock index 6528a6b7..0b45ce52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,7 +163,7 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "ros_logger" -version = "0.1.2" +version = "0.1.4" dependencies = [ "humantime", "is-terminal", diff --git a/Cargo.toml b/Cargo.toml index f35869bb..1126cff9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ros_logger" -version = "0.1.2" +version = "0.1.4" description = """ A logging implementation for `log` which is configured via an environment variable and creates tracing events for opentelemetry subscribers to subscribe to. diff --git a/src/lib.rs b/src/lib.rs index 85f47a08..e20338f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -907,36 +907,17 @@ impl Log for Logger { fn log(&self, record: &Record) { let max_packet_size = 65000; - let message = format!("{:#?}", record.args()); - - if self.matches(record) && message.as_bytes().len() < max_packet_size { - match record.level() { - Level::Error => tracing::event!( - tracing::Level::ERROR, - target = record.target(), - message = format!("{:#?}", record.args()) - ), - - Level::Warn => tracing::event!( - tracing::Level::WARN, - target = record.target(), - message = format!("{:#?}", record.args()) - ), - Level::Info => tracing::event!( - tracing::Level::INFO, - target = record.target(), - message = format!("{:#?}", record.args()) - ), - Level::Debug => tracing::event!( - tracing::Level::DEBUG, - target = record.target(), - message = format!("{:#?}", record.args()) - ), - Level::Trace => tracing::event!( - tracing::Level::TRACE, - target = record.target(), - message = format!("{:#?}", record.args()) - ), + + if self.matches(record) { + let message = format!("{:#?}", record.args()); + if message.as_bytes().len() < max_packet_size { + match record.level() { + Level::Error => tracing::error!(message), + Level::Warn => tracing::warn!(message), + Level::Info => tracing::info!(message), + Level::Debug => tracing::debug!(message), + Level::Trace => tracing::trace!(message), + } } // Log records are written to a thread-local buffer before being printed