Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
RS-1144: src details (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickfoxcroft authored Jun 23, 2023
2 parents 1432c79 + 46aba76 commit b2e441a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
64 changes: 59 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
}
}
}

Expand Down

0 comments on commit b2e441a

Please sign in to comment.