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

Commit

Permalink
RS-1136: Do not impede logging to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
rickfoxcroft authored Jun 15, 2023
2 parents bef70ab + eb5c05a commit 1432c79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 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.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.
Expand Down
41 changes: 11 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1432c79

Please sign in to comment.