Skip to content

Commit

Permalink
Format messages for slack.
Browse files Browse the repository at this point in the history
  • Loading branch information
ii-cruz committed Mar 25, 2024
1 parent 5a864a6 commit 27e59f3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/monitor_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ pub enum NotificationPriority {
Error,
}

impl NotificationPriority {
// Function to format the message based on its type
fn format_message(&self, log_message: &String) -> String {
match self {
Self::Info => format!(":information_source: *[INFO]* {}", log_message),
Self::Warning => format!(":warning: *[WARNING]* {}", log_message),
Self::Error => format!(":x: *[ERROR]* {}", log_message),
}
}
}

pub struct Logger {
webhook_url: String,
client: Client,
Expand All @@ -28,7 +39,7 @@ impl Logger {
) {
// Format the message payload as per Slack's requirements
let payload = json!({
"text": message,
"text": priority_type.format_message(message),
});

// Send the payload to the Slack webhook URL using a POST request
Expand Down

0 comments on commit 27e59f3

Please sign in to comment.