Skip to main content

Send logging messages to different channels (only Telegram for now)

Project description

logram

Python logger with different handlers

pip install logram

Add LOGGING configurations

Only different part is telegram handler

import logging
from logging.config import dictConfig
from logram.handlers import Telegram


Telegram.token = "20**:AA*****"
Telegram.chat_id = "-6***"

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "verbose": {
            "format": "[%(levelname)s] [%(asctime)s] [%(module)s] [line:%(lineno)d] %(message)s"
        },
        "simple": {"format": "%(levelname)s %(message)s"},
    },
    "handlers": {
        "file": {
            "level": "INFO",
            "class": "logging.FileHandler",
            "filename": "logs/log",
            "formatter": "verbose",
            "encoding": "UTF-8",
        },
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "formatter": "verbose",
        },
        "telegram": {
            "level": "WARNING",
            "class": "logram.handlers.Telegram",
            "formatter": "verbose",
        },
    },
    "loggers": {
        "django": {"handlers": ["console"], "level": "INFO", "propagate": True},
        "offices": {"handlers": ["console", "file"], "level": "INFO", "propagate": False},
        "smsreport": {"handlers": ["console", "telegram",  "file"], "level": "INFO", "propagate": True},
        "qinspect": {"handlers": ["console"], "level": "INFO", "propagate": True,},
    },
}

dictConfig(LOGGING)

Then this will send messages right into the Telegram Group

logging.warning("Send directly to the Telegram group")

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

logram-0.0.4.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file logram-0.0.4.tar.gz.

File metadata

  • Download URL: logram-0.0.4.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for logram-0.0.4.tar.gz
Algorithm Hash digest
SHA256 3020eb31827283660a29def74660f10801575210a10b35d5dff2bd338e6c5cda
MD5 a356fd6e93fecf098ea4ba105e8e9940
BLAKE2b-256 ec7642f1cb0fb14576686686b5dddf8bdf98164d93b48cbdd5188de78ac17692

See more details on using hashes here.

Supported by

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