cradle-plugin-api 0.1.2

API for cradle plugins
Documentation
use std::sync::Mutex;

static PLUGIN_LOG: Mutex<Vec<String>> = Mutex::new(Vec::new());

/// Stores a plugin log message for the cradle agent to drain later
pub fn cradle_log(msg: &str) {
    if let Ok(mut log) = PLUGIN_LOG.lock() {
        log.push(msg.to_string());
    }
}

/// Drains all stored logs and returns them
pub fn drain_log() -> Vec<String> {
    PLUGIN_LOG
        .lock()
        .map(|mut log| log.drain(..).collect())
        .unwrap_or_default()
}

/// Helpful macro to simplify basic logging without identification
#[macro_export]
macro_rules! clog {
    ($($arg:tt)*) => {
        $crate::cradle_log(&format!($($arg)*))
    };
}

/// Logging macro that logs with the plugin name for identification
#[macro_export]
macro_rules! plog {
    ($plugin:expr, $($arg:tt)*) => {
        $crate::cradle_log(&format!("[{}] {}", $plugin.name(), format!($($arg)*)))
    };
}