{"id":16057793,"url":"https://github.com/chinnichaitanya/python-discord-logger","last_synced_at":"2025-08-16T16:50:08.579Z","repository":{"id":57418409,"uuid":"257705861","full_name":"chinnichaitanya/python-discord-logger","owner":"chinnichaitanya","description":"🚀 Send custom messages to Discord to notify about application status, progress, errors, health checks etc.","archived":false,"fork":false,"pushed_at":"2025-02-18T16:43:38.000Z","size":1305,"stargazers_count":27,"open_issues_count":3,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T00:11:15.977Z","etag":null,"topics":["discord","discord-webhook","health-check","logging","messaging","monitoring","notification","notification-service","python","python-discord-logger"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/discord-logger/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chinnichaitanya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-21T20:17:30.000Z","updated_at":"2025-03-14T10:59:55.000Z","dependencies_parsed_at":"2025-02-18T17:36:05.814Z","dependency_job_id":null,"html_url":"https://github.com/chinnichaitanya/python-discord-logger","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinnichaitanya%2Fpython-discord-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinnichaitanya%2Fpython-discord-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinnichaitanya%2Fpython-discord-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinnichaitanya%2Fpython-discord-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chinnichaitanya","download_url":"https://codeload.github.com/chinnichaitanya/python-discord-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841156,"owners_count":20356441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-webhook","health-check","logging","messaging","monitoring","notification","notification-service","python","python-discord-logger"],"created_at":"2024-10-09T03:04:49.035Z","updated_at":"2025-03-16T07:32:35.149Z","avatar_url":"https://github.com/chinnichaitanya.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Discord Logger\n\nA custom message logger to Discord for Python 3.\nThis project was inspired from [`winston-discord-transport`](https://github.com/sidhantpanda/winston-discord-transport) for NodeJS\nand built using [discord-webhook](https://github.com/lovvskillz/python-discord-webhook), which offers an easy interface for\nconstructing and sending messages through a Discord webhook.\n\nIf you are looking for a Slack alternative, please check [python-slack-logger](https://github.com/chinnichaitanya/python-slack-logger).\n\n\u003ca href=\"https://pypi.org/project/discord-logger/\"\u003e\u003cimg alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/discord-logger\"\u003e\u003c/a\u003e\n[![PyPI version](https://badge.fury.io/py/discord-logger.svg)](https://badge.fury.io/py/discord-logger)\n\u003ca href=\"https://pepy.tech/project/discord-logger\"\u003e\u003cimg alt=\"Downloads\" src=\"https://static.pepy.tech/badge/discord-logger\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/discord-logger/#files\"\u003e\u003cimg alt=\"PyPI - Wheel\" src=\"https://img.shields.io/pypi/wheel/discord-logger\"\u003e\u003c/a\u003e\n[![License: MIT](https://img.shields.io/pypi/l/discord-logger)](https://github.com/chinnichaitanya/python-discord-logger/blob/master/LICENSE)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)\n\n## Install\n\nInstall via pip: `pip install discord-logger`\n\n## Basic Usage\n\n```python\nfrom discord_logger import DiscordLogger\n\noptions = {\n    \"application_name\": \"My Server\",\n    \"service_name\": \"Backend API\",\n    \"service_icon_url\": \"your icon url\",\n    \"service_environment\": \"Production\",\n    \"display_hostname\": True,\n    \"default_level\": \"info\",\n}\n\nlogger = DiscordLogger(webhook_url=\"your discord webhook url\", **options)\nlogger.construct(title=\"Health Check\", description=\"All services are running normally!\")\n\nresponse = logger.send()\n```\n\n![Image](https://raw.githubusercontent.com/chinnichaitanya/python-discord-logger/master/images/basic_message.png \"Basic Usage\")\n\n## Configure various options\n\nThere are numerous configurations available to customise the bot.\n\n```python\noptions = {\n    # Application name would replace the webhook name set during creating of the webhook\n    # It would appear as the name of the bot\n    # If unset, the default value would be \"Application\"\n    \"application_name\": \"My Server\",\n\n    # Service name would be the name of the service sending the message to your Discord channel\n    # This would usually be the name of the application sending the notification\n    # If unset, the default value would be \"Status Bot\"\n    \"service_name\": \"Backend API\",\n\n    # Service icon URL is the icon image for your application\n    # This field accepts a URL to the icon image\n    # If unspecified, the icon wouldn't be set\n    # If misconfigured, the icon wouldn't load and a blank space would appear before the service name\n    \"service_icon_url\": \"your icon url\",\n\n    # Usually services would run in staging and production environments\n    # This field is to specify the environment from which the application is reponding for easy identification\n    # If unset, this block would not appear in the message\n    \"service_environment\": \"Production\",\n\n    # An option to specify whether or not to display the hostname in the messages\n    # The hostname is set by default, but it could be disabled by specifically setting this to `False`\n    \"display_hostname\": True,\n\n    # The default importance level of the message\n    # The left bar color of the message would change depending on this\n    # Available options are\n    # - default: 2040357\n    # - error: 14362664\n    # - warn: 16497928\n    # - info: 2196944\n    # - verbose: 6559689\n    # - debug: 2196944\n    # - success: 2210373\n    # If the `error` field is set during the construction of the message, the `level` is automatically set to `error`\n    # If nothing is specified, `default` color would be used\n    \"default_level\": \"info\",\n}\n```\n\n## Emojis inbuilt! 😃\n\nAn appropriate emoji is automatically added before the title depending on the `level`.\n\nFollowing is the map between `level` and the emoji added.\n\n- default = `:loudspeaker:` 📢\n- error = `:x:` ❌\n- warn = `:warning:` ⚠️\n- info = `:bell:` 🔔\n- verbose = `:mega:` 📣\n- debug = `:microscope:` 🔬\n- success = `:rocket:` 🚀\n\n## Examples\n\n### Set Service Name, Icon and Environment for easy identification\n\nYou can configure the log message with service name, icon and environment for easy identification. The `Host` field which is the hostname of the server is automatically added for every message.\n\nYou can even send any meta information like the data in the variables, module names, metrics etc with the `metadata` field while constructing the message.\nThese data should be passed as a dictionary.\n\n```python\nfrom discord_logger import DiscordLogger\n\nwebhook_url = \"your discord webhook url\"\noptions = {\n    \"application_name\": \"My Server\",\n    \"service_name\": \"Backend API\",\n    \"service_icon_url\": \"your icon url\",\n    \"service_environment\": \"Production\",\n    \"default_level\": \"info\",\n}\n\nlogger = DiscordLogger(webhook_url=webhook_url, **options)\nlogger.construct(\n    title=\"Health Check\",\n    description=\"Issue in establishing DB connections!\",\n    error=\"Traceback (most recent call last):\\n ValueError: Database connect accepts only string as a parameter!\",\n    metadata={\"module\": \"DBConnector\", \"host\": 123.332},\n)\n\nresponse = logger.send()\n```\n\n![Image](https://raw.githubusercontent.com/chinnichaitanya/python-discord-logger/master/images/error_message.png \"Message with Service Name, Icon and Environment\")\n\n### Send messages without Hostname\n\nIn case you do not want the hostname to be displayed in the message, disable it by setting `\"display_hostname\": False` in the `options` as follows.\n\n```python\nfrom discord_logger import DiscordLogger\n\nwebhook_url = \"your discord webhook url\"\noptions = {\n    \"application_name\": \"My Server\",\n    \"service_name\": \"Backend API\",\n    \"service_icon_url\": \"your icon url\",\n    \"service_environment\": \"Production\",\n    \"default_level\": \"info\",\n    \"display_hostname\": False,\n}\n\nlogger = DiscordLogger(webhook_url=webhook_url, **options)\nlogger.construct(title=\"Health Check\", description=\"All services are running normally!\")\n\nresponse = logger.send()\n```\n\n![Image](https://raw.githubusercontent.com/chinnichaitanya/python-discord-logger/master/images/basic_message_without_hostname.png \"Basic message without Hostname\")\n\n### Send messages with different log-levels\n\nThe log-level indicates the importance of the message. It changes the color of the discord message in particular. Currently supported levels are,\n\n- `error`\n- `warn`\n- `info`\n- `verbose`\n- `debug`\n- `success`\n\nThe log-level can be set during construction of the message like through the parameter `level`.\n\nIf the parameter isn't provided, it'll be set to the one given in `default_level`. Any invalid input would be ignored and the log-level would be automatically be set to `default`.\n\nAny complicated nested dictionary can be passed to the `metadata` field and the message gets forrmatted accordingly for easy reading.\n\n```python\nfrom discord_logger import DiscordLogger\n\nwebhook_url = \"your discord webhook url\"\noptions = {\n    \"application_name\": \"My Server\",\n    \"service_name\": \"Backend API\",\n    \"service_icon_url\": \"your icon url\",\n    \"service_environment\": \"Production\",\n    \"default_level\": \"info\",\n}\n\nlogger = DiscordLogger(webhook_url=webhook_url, **options)\nlogger.construct(\n    title=\"Celery Task Manager\",\n    description=\"Successfully completed training job for model v1.3.3!\",\n    level=\"success\",\n    metadata={\n        \"Metrics\": {\n            \"Accuracy\": 78.9,\n            \"Inference time\": \"0.8 sec\",\n            \"Model size\": \"32 MB\",\n        },\n        \"Deployment status\": \"progress\",\n    },\n)\n\nresponse = logger.send()\n```\n\n![Image](https://raw.githubusercontent.com/chinnichaitanya/python-discord-logger/master/images/success_message.png \"Message with success log-level\")\n\n### Send complete error traceback\n\nThe `error` field can contain any error message. It will be automatically be formatted in the final message. For example, you can send a complete traceback of an error message to debug faster!\n\n```python\nimport traceback\n\nfrom discord_logger import DiscordLogger\n\n\ndef get_traceback(e):\n    tb = (\n        \"Traceback (most recent call last):\\n\"\n        + \"\".join(traceback.format_list(traceback.extract_tb(e.__traceback__)))\n        + type(e).__name__\n        + \": \"\n        + str(e)\n    )\n    return tb\n\n\nwebhook_url = \"your discord webhook url\"\noptions = {\n    \"application_name\": \"My Server\",\n    \"service_name\": \"Backend API\",\n    \"service_icon_url\": \"your icon url\",\n    \"service_environment\": \"Production\",\n    \"default_level\": \"info\",\n}\n\nerr = KeyError(\"`email` field cannot be None\")\n\nlogger = DiscordLogger(webhook_url=webhook_url, **options)\nlogger.construct(\n    title=\"Runtime Exception\",\n    description=err.__str__(),\n    error=get_traceback(err),\n    metadata={\"email\": None, \"module\": \"auth\", \"method\": \"POST\"},\n)\n\nresponse = logger.send()\n```\n\n![Image](https://raw.githubusercontent.com/chinnichaitanya/python-discord-logger/master/images/complete_error_traceback.png \"Message with complete error traceback\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinnichaitanya%2Fpython-discord-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchinnichaitanya%2Fpython-discord-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinnichaitanya%2Fpython-discord-logger/lists"}