Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Releases: pinax-network/substreams-sink-winston

v0.1.2

20 Feb 19:49
Compare
Choose a tag to compare
  • Add Meta struct
#[cfg(test)]
mod tests {
    use crate::{Logger, Meta};
    use std::collections::HashMap;

    #[test]
    fn test_meta_array() {
        let logger = Logger::new("user-service");
        let items = vec!["value"];
        let meta = Meta::from(items);

        logger.info("info message").with(meta);
    }

    #[test]
    fn test_meta_hashmap() {
        let logger = Logger::new("user-service");
        let items = HashMap::from([("key".to_string(), "value".to_string())]);
        let meta = Meta::from(items);

        logger.info("info message").with(meta);
    }

    #[test]
    fn test_meta_array_object() {
        let logger = Logger::new("user-service");
        let meta = Meta::from(vec![["key", "value"]]);

        logger.info("info message").with(meta);
    }

    #[test]
    fn test_meta_insert() {
        let logger = Logger::new("user-service");
        let mut meta = Meta::new();
        meta.insert("key", "value");

        logger.info("info message").with(meta);
    }

    #[test]
    fn test_meta_push() {
        let logger = Logger::new("user-service");
        let mut meta = Meta::new();
        meta.push("value");

        logger.info("info message").with(meta);
    }
}

v0.1.1

19 Feb 20:35
Compare
Choose a tag to compare

Substreams Winston Logger sink module

github crates.io docs.rs GitHub Workflow Status

substreams-sink-winston is a tool that allows developers to pipe data extracted metrics from a blockchain into a standard Winston Logging message conforming to the severity ordering specified by RFC5424.

📖 Documentation

https://docs.rs/substreams-sink-winston

Further resources

Related Sinks

  • Substreams GoogleSheet sink module
  • Substreams CSV sink module
  • Substreams Telegram sink module
  • Substreams Discord sink module

🛠 Feature Roadmap

Create Logger

  • service
  • defaultMeta

Logging

  • Emergency: system is unusable
  • Alert: action must be taken immediately
  • Critical: critical conditions
  • Error: error conditions
  • Warning: warning conditions
  • Notice: normal but significant condition
  • Informational: informational messages
  • Debug: debug-level messages

Filtering info Objects

  • ignorePrivate
  • private

Install

$ cargo add substreams-sink-winston

Quickstart

Cargo.toml

[dependencies]
substreams = "0.5"
substreams-sink-winston = "0.1"

src/lib.rs

use std::collections::HashMap;
use substreams::errors::Error;
use substreams_sink_winston::{Logger, LoggerOperations};

#[substreams::handlers::map]
fn prom_out(
    ... some stores ...
) -> Result<LoggerOperations, Error> {
    // Initialize Winston Logger operations container
    let mut log_ops: LoggerOperations = Default::default();

    // Create Logger
    // ==============
    let mut logger = Logger::from("user-service");

    // Informational: informational messages
    log_ops.push(logger.info("info message"));

    // Error: error conditions
    log_ops.push(logger.error("error message"));

    // Create a HashMap of metadata
    let meta = HashMap::from([("label1".to_string(), "value1".to_string())]);
    log_ops.push(logger.info("message").with(meta));

    Ok(log_ops)
}