Skip to main content

embedded_wg_display/runtime/host_api/
logging.rs

1#![doc = "Implementation of the `logging` WIT interface.\n\n```wit"]
2#![doc = include_str!("wit/logging.wit")]
3#![doc = "```"]
4
5use crate::runtime::WidgetState;
6use crate::runtime::widget::widget::logging;
7use alloc::string::String;
8
9use defmt::{debug, error, info, warn};
10
11impl logging::Host for WidgetState {
12    fn log(&mut self, level: logging::Level, context: String, message: String) {
13        const PREFIX: &str = "WIDGET";
14        match level {
15            logging::Level::Debug => {
16                debug!("{}: {}: {}", PREFIX, context.as_str(), message.as_str())
17            }
18            logging::Level::Info => info!("{}: {}: {}", PREFIX, context.as_str(), message.as_str()),
19            logging::Level::Warn => warn!("{}: {}: {}", PREFIX, context.as_str(), message.as_str()),
20            logging::Level::Error => {
21                error!("{}: {}: {}", PREFIX, context.as_str(), message.as_str())
22            }
23        }
24    }
25}