veecle_osal_freertos/
log.rs

1//! Logging related system utilities.
2
3#[cfg(not(all(target_arch = "arm", target_os = "none")))]
4use std::io::Write;
5
6pub use veecle_osal_api::log::LogTarget;
7
8/// Implements the [`LogTarget`] trait.
9#[derive(Debug)]
10pub struct Log;
11
12impl LogTarget for Log {
13    type Time = crate::time::Time;
14
15    fn init() {
16        #[cfg(all(target_arch = "arm", target_os = "none"))]
17        rtt_target::rtt_init_print!();
18    }
19
20    fn println(args: core::fmt::Arguments<'_>) {
21        // TODO: How should this sort of `cfg` be handled.
22        #[cfg(all(target_arch = "arm", target_os = "none"))]
23        // `"{args}"` _would_ work, except `rtt_target::rprintln!` has a buggy macro arm that bypasses the formatting
24        // infrastructure on a single expression.
25        rtt_target::rprintln!("{}", args);
26
27        #[cfg(not(all(target_arch = "arm", target_os = "none")))]
28        // this is a logger, ignore any errors writing
29        let _ = std::writeln!(std::io::stdout(), "{args}");
30    }
31}