cotyledon 0.1.0

Framework for writing sprouts — sandboxed, event-driven on-chain trading bots.
Documentation
//! Observability handles — logs and metrics.

use crate::host;

/// Logging. Messages are written to the sprout's stdout/stderr, which the engine
/// captures and stores — so `ctx.log().info(..)` and a plain `println!(..)` are
/// equivalent. Logging is deliberately *not* a first-class engine call.
pub struct Log;

impl Log {
    pub fn info(&self, msg: &str) {
        println!("INFO  {msg}");
    }

    pub fn warn(&self, msg: &str) {
        println!("WARN  {msg}");
    }

    pub fn error(&self, msg: &str) {
        eprintln!("ERROR {msg}");
    }
}

/// Metrics the platform charts for the sprout.
pub struct Metric;

impl Metric {
    /// Increment a counter by `n`.
    pub fn count(&self, name: &str, n: u64) {
        host::metric(name, n as f64);
    }

    /// Set a gauge to `value`.
    pub fn gauge(&self, name: &str, value: f64) {
        host::metric(name, value);
    }
}