Skip to content

Commit

Permalink
fix(LoggingConsumer): trim newline char from the mirrored messages (#699
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DDtKey authored Jul 18, 2024
1 parent 1c83196 commit 64b635d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions testcontainers/src/core/logs/consumer/logging_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl LoggingConsumer {
self
}

fn format_message<'a>(&self, message: &'a bytes::Bytes) -> Cow<'a, str> {
fn format_message<'a>(&self, message: &'a str) -> Cow<'a, str> {
// Remove trailing newlines
let message = String::from_utf8_lossy(message);
let message = message.trim_end_matches(|c| c == '\n' || c == '\r');

Check warning on line 47 in testcontainers/src/core/logs/consumer/logging_consumer.rs

View workflow job for this annotation

GitHub Actions / clippy

this manual char comparison can be written more succinctly

warning: this manual char comparison can be written more succinctly --> testcontainers/src/core/logs/consumer/logging_consumer.rs:47:48 | 47 | let message = message.trim_end_matches(|c| c == '\n' || c == '\r'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using an array of `char`: `['\n', '\r']` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison = note: `#[warn(clippy::manual_pattern_char_comparison)]` on by default

if let Some(prefix) = &self.prefix {
Cow::Owned(format!("{} {}", prefix, message))
} else {
message
Cow::Borrowed(message)
}
}
}
Expand All @@ -65,10 +65,18 @@ impl LogConsumer for LoggingConsumer {
async move {
match record {
LogFrame::StdOut(bytes) => {
log::log!(self.stdout_level, "{}", self.format_message(bytes));
log::log!(
self.stdout_level,
"{}",
self.format_message(&String::from_utf8_lossy(bytes))
);
}
LogFrame::StdErr(bytes) => {
log::log!(self.stderr_level, "{}", self.format_message(bytes));
log::log!(
self.stderr_level,
"{}",
self.format_message(&String::from_utf8_lossy(bytes))
);
}
}
}
Expand Down

0 comments on commit 64b635d

Please sign in to comment.