Slack Logger ๐งต
A lightweight async logger for sending structured and text-based logs to Slack from your Rust applications.
โจ Features
- โ
Simple
log_info(), log_error(), log_warn() style methods
- โ
Block-style logs with key-value pairs
- โ
Auto-pretty-prints complex JSON data
- โ
Runs asynchronously using
tokio::spawn
- โ
Works great for production observability and alerts
๐ฆ Installation
Add to your Cargo.toml:
[dependencies]
slack_log = "0.1"
or
cargo install slack-log
โ๏ธ Initialization
Before using, initialize once:
use slack_log::{slack_log_initialize, SlackConfig};
slack_log_initialize(SlackConfig {
webhook_url: "https://hooks.slack.com/services/...".into(),
debugger: true,
});
๐งช Usage Examples
๐ณ Block-style Logs
use slack_log::{log_block_success, log_block_error, log_block_info, log_block_warn, log_block, block_fields};
use serde_json::json;
use chrono::Utc;
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 }]) },
{ title: "to_string_pretty", value: serde_json::to_string_pretty(&json!([{ "a": 1 }, { "b": 2 }])).unwrap() }
];
log_block_success("Ravi bhai ka code", &fields);
log_block_error("Startup", &fields);
log_block_info("Startup", &fields);
log_block_warn("Startup", &fields);
log_block("Startup", &fields);
๐ฌ Simple Logs
use slack_log::{log, log_info, log_warn, log_success, log_error};
use serde_json::json;
log_info("App started \njay here!!!");
log_warn(1234);
log_success(true);
log_error(json!({ "event": "shutdown", "reason": "manual" }));
let data = json!([{ "a": 1 }, { "b": 2 }]);
log(serde_json::to_string_pretty(&data).unwrap());
๐งฑ Macro Support
Create blocks easily with:
let fields = block_fields![
{ title: "Key", value: "Value" },
{ title: "Another", value: 123 }
];
๐ License
MIT OR Apache-2.0