Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decoder: Fix that defmt::println! shows leading space when timestamps are disabled #608

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions decoder/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ pub fn log_defmt(
line: Option<u32>,
module_path: Option<&str>,
) {
let timestamp = frame
.display_timestamp()
.map(|display| display.to_string())
.unwrap_or_default();
let timestamp = frame.display_timestamp().map(|display| display.to_string());
let display = frame.display_message();

if let Some(level) = frame.level() {
Expand All @@ -42,7 +39,7 @@ pub fn log_defmt(
crate::Level::Error => Level::Error,
};

let target = format!("{}{}", DEFMT_TARGET_MARKER, timestamp);
let target = format!("{}{}", DEFMT_TARGET_MARKER, timestamp.unwrap_or_default());
log::logger().log(
&Record::builder()
.args(format_args!("{}", display))
Expand All @@ -56,7 +53,8 @@ pub fn log_defmt(
} else {
let stdout = io::stdout();
let mut sink = stdout.lock();
writeln!(&mut sink, "{} {}", timestamp, display).ok();
let timestamp = timestamp.map(|ts| format!("{} ", ts)).unwrap_or_default();
writeln!(&mut sink, "{}{}", timestamp, display).ok();
print_location(&mut sink, file, line, module_path).ok();
}
}
Expand Down