gale.log.discord_webhook_handler module

This file contains the implementation of the class DiscordWebhookHandler: a logging.Handler that posts each log record to a Discord channel through an incoming webhook.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.log.discord_webhook_handler.DiscordWebhookHandler(webhook_url, username=None, timeout=2.0)[source]

Bases: Handler

Posts every log record to a Discord channel through an incoming webhook — a common, zero-infrastructure way for a small/solo team to get pinged about errors and warnings without standing up a full log aggregation stack. Uses only the standard library.

Since pinging a channel for every single INFO line would be noisy, this is typically attached with a raised level, e.g. only WARNING/ERROR and above:

Usage example:

from gale.log import add_handler from gale.log.level import LogLevel from gale.log.discord_webhook_handler import DiscordWebhookHandler

handler = DiscordWebhookHandler(

https://discord.com/api/webhooks/<id>/<token>”, username=”space_trip”

) handler.setLevel(LogLevel.WARNING) add_handler(handler)

Parameters:
  • webhook_url (str)

  • username (str | None)

  • timeout (float)

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

Parameters:

record (LogRecord)

Return type:

None