A Python package for logging error messages to a Slack channel
Project description
Medianova Slack Logger
MN Slack Logger is a Python package for logging error messages to a Slack channel.
Getting Started
To use MN Slack Logger, follow these steps:
Prerequisites
First, add MN Slack Logger to your project
pip install mn-slack-logger
Usage
MN Slack Logger can be used to send messages of various levels (info, warning, error) to your Slack channel. Here's how you can use it:
from mn_slack_logger import SlackLogger
logger = SlackLogger(slack_url="https://slack-webhook-url", slack_user="Logger")
logger.log("An example message", level="info")
logger.log("An example warning", level="warning")
logger.log("An example error", level="error", error="traceback text...")
For handling long traceback messages, MN Slack Logger shortens them automatically to fit Slack's message length limits.
Usage with FastAPI
MN Slack Logger can be integrated into a FastAPI application to log messages to Slack. Here's an example of how you can use it in your FastAPI application:
from fastapi import FastAPI, HTTPException
from mn_slack_logger import SlackLogger
app = FastAPI()
logger = SlackLogger(slack_url="https://slack-webhook-url", slack_user="FastAPI Logger")
@app.exception_handler(HTTPException)
async def http_exception_handler(request, exc):
logger.log(f"HTTP Exception: {exc.detail}", level="error", error=str(exc))
return {"detail": exc.detail}
@app.get("/")
async def read_root():
return {"Hello": "World"}
@app.get("/error")
async def cause_error():
raise HTTPException(status_code=400, detail="This is a test error")
This example sets up a basic FastAPI application with an exception handler that logs HTTP exceptions to Slack using MN Slack Logger.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mn_slack_logger-0.0.2.tar.gz
.
File metadata
- Download URL: mn_slack_logger-0.0.2.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa8be7301ed0b6bb282253cd5ff284495169d3344329c87ba56c0b9b92b56d12 |
|
MD5 | 6f41aae1c98d300003104e1b709fe3cc |
|
BLAKE2b-256 | b155b9834e73ffc8cee21c62a7ea0776cbdcdb0c8aa387491156de001940cd83 |
File details
Details for the file mn_slack_logger-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: mn_slack_logger-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8586006c2593893ecb84e795ab3377d26b1b0a0121640f8aa708d197890812b |
|
MD5 | a2189df43876788e38553c00575c02cc |
|
BLAKE2b-256 | 437cd2a15e338182c2f3c6c895a923213e3f81658b195116a99b256f8fd45497 |