logging: implement rtt logging output

This commit is contained in:
2025-12-07 13:07:56 +01:00
parent da7511aec7
commit 20cc634714
2 changed files with 7 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ wokwi = ["max-usb-power"]
mpu = ["dep:mpu6050-dmp"]
gps = ["dep:nmea"]
oled = ["dep:ssd1306"]
rtt = ["dep:rtt-target"]
demo = []
[dependencies]

View File

@@ -22,6 +22,9 @@ static LOGGER: StaticCell<RenderbugLogger> = StaticCell::new();
impl RenderbugLogger {
pub fn init_logger() {
#[cfg(feature = "rtt")]
rtt_target::rtt_init_print!(rtt_target::ChannelMode::BlockIfFull);
let logger = LOGGER.init(Default::default());
unsafe {
log::set_logger_racy(logger).ok();
@@ -62,6 +65,9 @@ impl log::Log for RenderbugLogger {
};
let suffix = filename.split('/').next_back().unwrap();
self.lock.lock(|_| {
#[cfg(feature = "rtt")]
rtt_target::rprintln!("{}{}\t{}{}/{}:{}{}\t{}{}", color, record.level(), GREY, prefix, suffix, record.line().map_or(0, |f| {f}), RESET, record.args(), RESET);
println!("{color}{}\t{GREY}{prefix}/{suffix}:{}{RESET}\t{}{RESET}", record.level(), record.line().map_or(0, |f| {f}), record.args());
});
}