Skip to content

Commit

Permalink
Display timestamp, useful to find timing problem
Browse files Browse the repository at this point in the history
  • Loading branch information
davidqge committed Sep 17, 2024
1 parent 46b5b8d commit 71d7d3e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Fixed
- espflash defmt log didn't display timestamp, according to [defmt doc](https://defmt.ferrous-systems.com/timestamps).

### Changed

Expand Down
32 changes: 3 additions & 29 deletions espflash/src/cli/monitor/parser/esp_defmt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::io::Write;

use crossterm::{
style::{Color, Print, PrintStyledContent, Stylize},
QueueableCommand,
};
use crossterm::{style::Print, QueueableCommand};
use defmt_decoder::{Frame, Table};
use miette::{bail, Context, Diagnostic, Result};
use thiserror::Error;
Expand Down Expand Up @@ -140,31 +137,8 @@ impl EspDefmt {
}

fn handle_defmt(frame: Frame<'_>, out: &mut dyn Write) {
match frame.level() {
Some(level) => {
let color = match level {
defmt_parser::Level::Trace => Color::Cyan,
defmt_parser::Level::Debug => Color::Blue,
defmt_parser::Level::Info => Color::Green,
defmt_parser::Level::Warn => Color::Yellow,
defmt_parser::Level::Error => Color::Red,
};

// Print the level before each line.
let level = level.as_str().to_uppercase();
for line in frame.display_message().to_string().lines() {
out.queue(PrintStyledContent(
format!("[{level}] - {line}\r\n").with(color),
))
.unwrap();
}
}
None => {
out.queue(Print(frame.display_message().to_string()))
.unwrap();
out.queue(Print("\r\n")).unwrap();
}
}
out.queue(Print(frame.display(true).to_string())).unwrap();
out.queue(Print("\r\n")).unwrap();

out.flush().unwrap();
}
Expand Down

0 comments on commit 71d7d3e

Please sign in to comment.