Skip to content

Slack ​

SlackHandler sends log entries to a Slack channel via incoming webhook. No extra dependencies required.

Installation ​

This integration uses Python's standard library (urllib.request). No additional packages needed.

bash
uv add logly
bash
pip install logly

Missing Dependency

If slack-sdk is not installed, you'll see:

ModuleNotFoundError: No module named 'slack_sdk'

Usage ​

python
from logly import logger
from logly.integrations.slack import SlackHandler

handler = SlackHandler(
    "https://hooks.slack.com/services/...",
    channel="#logs",
    username="Logly Bot",
)
logger.add(handler, level="WARNING")

Constructor Args ​

ArgumentTypeDefaultDescription
webhook_urlstr""Slack incoming webhook URL
channelstr | NoneNoneChannel override for the webhook
usernamestr | NoneNoneUsername override for the webhook
icon_emojistr | NoneNoneEmoji override for the webhook icon
timeoutfloat10.0HTTP request timeout in seconds

Tips ​

  • Use a dedicated Slack channel for production alerts to keep them separate from development noise.
  • Set icon_emoji to ":rotating_light:" for critical alerts.

Full Example ​

python
from logly import logger
from logly.integrations.slack import SlackHandler

handler = SlackHandler(
    webhook_url="https://hooks.slack.com/services/T00/B00/xxx",
    channel="#ops-alerts",
    username="Logly Alerts",
    icon_emoji=":warning:",
)
logger.add(handler, level="WARNING")

logger.warning("High memory usage detected", usage="87%")
logger.error("Database connection pool exhausted")

Released under the MIT License.