# 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`:
```toml
[dependencies]
slack_log = "2.0.0"
```
or install binary crate (if CLI exposed):
```bash
cargo install slack-log
```
---
## โ๏ธ Initialization
Initialize once before any logging:
```rust
use slack_log::{slack_log_initialize, SlackConfig};
slack_log_initialize(SlackConfig {
webhook_url: "https://hooks.slack.com/services/...",
debugger: true,
});
```
---
## ๐ฌ Simple Logs
```rust
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)
```rust
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
```rust
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
```rust
use slack_log::BlockField;
let fields = vec![
BlockField::new("Key", "Value"),
BlockField::new("Count", 123)
];
```
---
## ๐ License
MIT OR Apache-2.0