Skip to main content

slack_exception_logger

A Python library that allows you to log exceptions to a Slack channel using the Slack Webhook API. It also allows you to log information messages, success messages, warning messages and error messages to a Slack channel.

Installation

You can install slack_exception_logger using pip:

pip install slack_exception_logger

Usage

To use slack_exception_logger, you need to import the SlackExceptionLogger class from the library and initialize an instance of the class:

from slack_exception_logger import SlackExceptionLogger
slack_logger = SlackExceptionLogger()

Logging Exceptions

You can log an exception to Slack by calling the push_to_slack method and passing the exception object as an argument whenever an exception occurs in your code:

try:
    # Your code that may throw an exception
    1/0
except Exception as e:
    slack_logger.push_to_slack(e)

If the exception object is an instance of the Exception class, it will log the complete exception details, which includes the exception type, value, and the stack trace. If it is a string, it will log it as an information message.

Logging Information Messages

You can log an information message to Slack by calling the info method and passing the message text as an argument:

slack_logger.info("This is an information message.")

Logging Success Messages

You can log a success message to Slack by calling the success method and passing the message text as an argument:

slack_logger.success("This is a success message.")

Logging Warning Messages

You can log a warning message to Slack by calling the warn method and passing the message text as an argument:

slack_logger.warn("This is a warning message.")

Logging Error Messages

You can log an error message to Slack by calling the error method and passing the message text as an argument:

slack_logger.error("This is an error message.")

Configuration

Before using the library, you need to set the following environment variables:

SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/your-webhook-url'
SLACK_CHANNEL = '#exceptions'

You can get the Webhook URL by creating an incoming webhook in your Slack workspace. Click here follow the tutorial to know how enable webhooks in your slack.

Note

This library uses the traceback module to get the complete exception details, which includes the exception type, value, and the stack trace, and then sends the traceback information to the slack channel. It is also possible to filter out the sensitive information from the traceback before sending it to slack.

License

This library is licensed under the MIT License.

Contribution

We welcome contributions to this library. If you have an idea for a new feature or have found a bug, please open an issue on Github.

Buy me a Coffee

ko-fi

Release files for slack-exception-logger 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slack-exception-logger 0.3
File Size Uploaded
slack_exception_logger-0.3.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slack-exception-logger 0.3
File Interpreter ABI Platform
slack_exception_logger-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / slack_exception_logger-0.3.tar.gz

Download URL slack_exception_logger-0.3.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
371825b8e32bb85dbb48d0dbc57d61dd21a0fc7b1ce64169fd93b6fa2573476c
BLAKE2b-256 checksum
How to use checksums
35696e03871018a59f3ac893d487bc18990b7646f4a3ddcc871374560943b107
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.1

Release files / slack_exception_logger-0.3-py3-none-any.whl

Download URL slack_exception_logger-0.3-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16164cfb3530d0a1203f587045cc590e18b5ee8ca7310d2dde13d56b989c113e
BLAKE2b-256 checksum
How to use checksums
c4cc22b705ed9a4b44250470ba48064da649f8de6bac12d5c103b99843418747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2

1 release file

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page