fuchsia_triage/
inspect_logger.rs#[cfg(target_os = "fuchsia")]
mod target {
use fuchsia_inspect_contrib::inspect_log;
use fuchsia_inspect_contrib::nodes::BoundedListNode;
use std::sync::{LazyLock, Mutex};
struct LogHolder {
list: Mutex<Option<BoundedListNode>>,
}
impl LogHolder {
fn new() -> Self {
LogHolder { list: Mutex::new(None) }
}
}
static LOGGER: LazyLock<LogHolder> = LazyLock::new(LogHolder::new);
pub fn set_log_list_node(node: BoundedListNode) {
*LOGGER.list.lock().unwrap() = Some(node);
}
pub(crate) fn log_warn(message: &str, namespace: &str, name: &str, error: &str) {
log_problem("warn", message, namespace, name, error);
}
pub(crate) fn log_error(message: &str, namespace: &str, name: &str, error: &str) {
log_problem("error", message, namespace, name, error);
}
fn log_problem(level: &str, message: &str, namespace: &str, name: &str, error: &str) {
let Some(ref mut list) = *LOGGER.list.lock().unwrap() else {
return;
};
inspect_log!(
list,
level: level,
message: message,
namespace: namespace,
name: name,
error: error
);
}
}
#[cfg(target_os = "fuchsia")]
pub use target::*;
#[cfg(not(target_os = "fuchsia"))]
mod host {
pub(crate) fn log_warn(_message: &str, _namespace: &str, _name: &str, _error: &str) {}
pub(crate) fn log_error(_message: &str, _namespace: &str, _name: &str, _error: &str) {}
}
#[cfg(not(target_os = "fuchsia"))]
pub(crate) use host::*;