Skip to main content

A Python package for logging error messages to a Slack channel

Project description


Logo

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

(back to top)

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.

(back to top)

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.

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mn_slack_logger-0.0.8.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mn_slack_logger-0.0.8-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file mn_slack_logger-0.0.8.tar.gz.

File metadata

  • Download URL: mn_slack_logger-0.0.8.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mn_slack_logger-0.0.8.tar.gz
Algorithm Hash digest
SHA256 93c4bfe292fcae5b180edf26606a2c58185e0c3e2341dd1c71659728292de8dd
MD5 487765ddcad9e09762bef4c5ddc752c7
BLAKE2b-256 1a82827a2a92af538bb72ef52ecf2317839eb230aa3404c908bdd51efeea21e2

See more details on using hashes here.

File details

Details for the file mn_slack_logger-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for mn_slack_logger-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 38cd61b48f9cdcec5532d67493b25ff5e2ea8fb44c99513b4a6fb9e75645a342
MD5 0b9f6288f9168304ba50f1ae77491e24
BLAKE2b-256 f79d0a292ab5aa024c8ebee9b5d82abd7076687d3cde4a7c924e997cee5d98ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page