diff --git a/Cargo.lock b/Cargo.lock index 0b45ce52..e0118e18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,7 +163,7 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "ros_logger" -version = "0.1.4" +version = "0.1.6" dependencies = [ "humantime", "is-terminal", diff --git a/Cargo.toml b/Cargo.toml index 1126cff9..f13c0624 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ros_logger" -version = "0.1.4" +version = "0.1.6" 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 e20338f9..d5758e00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -900,6 +900,13 @@ impl Logger { } } +struct Source { + line_no: u32, + file_path: String, + namespace: String, + target: String, +} + impl Log for Logger { fn enabled(&self, metadata: &Metadata) -> bool { self.filter.enabled(metadata) @@ -910,13 +917,60 @@ impl Log for Logger { if self.matches(record) { let message = format!("{:#?}", record.args()); + + let src = Source { + line_no: record.line().unwrap_or(0), + file_path: record.file().unwrap_or("default").to_string(), + namespace: record.module_path().unwrap_or("default").to_string(), + target: record.target().to_string(), + }; 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), + Level::Error => { + tracing::error!( + message, + src.line_no, + src.file_path, + src.namespace, + src.target + ) + } + Level::Warn => { + tracing::warn!( + message, + src.line_no, + src.file_path, + src.namespace, + src.target + ) + } + Level::Info => { + tracing::info!( + message, + src.line_no, + src.file_path, + src.namespace, + src.target + ) + } + Level::Debug => { + tracing::debug!( + message, + src.line_no, + src.file_path, + src.namespace, + src.target + ) + } + Level::Trace => { + tracing::trace!( + message, + src.line_no, + src.file_path, + src.namespace, + src.target + ) + } } }