cradle-plugin-api 0.1.0

API for cradle plugins
Documentation
use std::cell::RefCell;

thread_local! {
    static PLUGIN_LOG: RefCell<Vec<String>> = const { RefCell::new(Vec::new()) };
}

/// Stores a plugin log message for the cradle agent to drain later
pub fn cradle_log(msg: &str) {
    PLUGIN_LOG.with(|log| {
        log.borrow_mut().push(msg.to_string());
    });
}

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

/// 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)*)))
    };
}