Skip to main content

cotyledon/
obs.rs

1//! Observability handles — logs and metrics.
2
3use crate::host;
4
5/// Logging. Messages are written to the sprout's stdout/stderr, which the engine
6/// captures and stores — so `ctx.log().info(..)` and a plain `println!(..)` are
7/// equivalent. Logging is deliberately *not* a first-class engine call.
8pub struct Log;
9
10impl Log {
11    pub fn info(&self, msg: &str) {
12        println!("INFO  {msg}");
13    }
14
15    pub fn warn(&self, msg: &str) {
16        println!("WARN  {msg}");
17    }
18
19    pub fn error(&self, msg: &str) {
20        eprintln!("ERROR {msg}");
21    }
22}
23
24/// Metrics the platform charts for the sprout.
25pub struct Metric;
26
27impl Metric {
28    /// Increment a counter by `n`.
29    pub fn count(&self, name: &str, n: u64) {
30        host::metric(name, n as f64);
31    }
32
33    /// Set a gauge to `value`.
34    pub fn gauge(&self, name: &str, value: f64) {
35        host::metric(name, value);
36    }
37}