#logging #slack #jkg #jaykumar

slack-log

Slack log for sending plain and block messages using Slack webhook

3 stable releases

2.1.0 Aug 4, 2025
2.0.0 Aug 4, 2025
1.1.3 Jul 31, 2025

#431 in Debugging

MIT license

17KB
224 lines

Slack Logger ๐Ÿงต

A lightweight async logger for sending structured and text-based logs to Slack from your Rust applications.

โœจ Features

  • โœ… Unified slack.log, slack.success, slack.error_block-style API
  • โœ… Block-style logs with key-value pairs
  • โœ… Auto-pretty-prints complex JSON data
  • โœ… Runs asynchronously using tokio::spawn
  • โœ… Ideal for production observability and alerts

๐Ÿ“ฆ Installation

Add to your Cargo.toml:

[dependencies]
slack_log = "2.0.0"

or install binary crate (if CLI exposed):

cargo install slack-log

โš™๏ธ Initialization

Initialize once before any logging:

use slack_log::{slack_log_initialize, SlackConfig};

slack_log_initialize(SlackConfig {
    webhook_url: "https://hooks.slack.com/services/...",
    debugger: true,
});

๐Ÿ’ฌ Simple Logs

use slack_log::slack;
use serde_json::json;

slack.log("App started successfully");
slack.warn("High memory usage");
slack.success(true);
slack.error(json!({ "event": "shutdown", "reason": "manual" }));

let data = json!([{ "a": 1 }, { "b": 2 }]);
slack.log(serde_json::to_string_pretty(&data).unwrap());

๐Ÿ”ณ Block-style Logs - Format 1: (Preferred)

use slack_log::{slack, block_fields};
use serde_json::json;

let fields = block_fields![
    { title: "Service", value: "UI Indexer" },
    { title: "Price", value: 50000 },
    { title: "Boolean", value: false },
    { title: "Time", value: chrono::Utc::now().to_string() },
    { title: "JSON", value: json!([{ "a": 1 }, { "b": 2 }]) }
];

slack.block("Deployment Success", &fields);
slack.success_block("Deployment Success", &fields);
slack.error_block("Startup Error", &fields);
slack.info_block("Service Info", &fields);
slack.warn_block("Warning Signal", &fields);

๐Ÿ”ณ Block-style Logs - Format 2

use slack_log::{slack, BlockField};
use serde_json::json;

let fields = vec![
    BlockField::new("Service", "UI Indexer"),
    BlockField::new("Price", 50000),
    BlockField::new("Boolean", false),
    BlockField::new("Time", chrono::Utc::now().to_string()),
    BlockField::new("JSON", json!([{ "a": 1 }, { "b": 2 }])),
];

slack.block("Deployment Success", &fields);
slack.success_block("Deployment Success", &fields);
slack.error_block("Startup Error", &fields);
slack.info_block("Service Info", &fields);
slack.warn_block("Warning Signal", &fields);

๐Ÿงฑ BlockField Builder

use slack_log::BlockField;

let fields = vec![
    BlockField::new("Key", "Value"),
    BlockField::new("Count", 123)
];

๐Ÿ“ License

MIT OR Apache-2.0

Dependencies

~6โ€“22MB
~244K SLoC