thermostat/src/init_log.rs

27 lines
768 B
Rust
Raw Normal View History

2020-12-13 09:24:29 +08:00
#[cfg(not(feature = "semihosting"))]
2020-09-11 05:17:31 +08:00
use crate::usb;
2020-03-12 07:50:24 +08:00
#[cfg(not(feature = "semihosting"))]
2020-09-11 05:17:31 +08:00
pub fn init_log() {
2020-09-25 05:11:05 +08:00
static USB_LOGGER: usb::Logger = usb::Logger;
2020-09-18 06:55:53 +08:00
let _ = log::set_logger(&USB_LOGGER);
log::set_max_level(log::LevelFilter::Debug);
2020-09-11 05:17:31 +08:00
}
2020-03-12 07:50:24 +08:00
#[cfg(feature = "semihosting")]
pub fn init_log() {
use log::LevelFilter;
use cortex_m_log::log::{Logger, init};
use cortex_m_log::printer::semihosting::{InterruptOk, hio::HStdout};
static mut LOGGER: Option<Logger<InterruptOk<HStdout>>> = None;
let logger = Logger {
inner: InterruptOk::<_>::stdout().expect("semihosting stdout"),
level: LevelFilter::Info,
};
let logger = unsafe {
LOGGER.get_or_insert(logger)
};
init(logger).expect("set logger");
}