Skip to content

parikls/python-telegram-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project is no longer maintaned.

Python Telegram Logger

Simple logger which dispatch messages to a telegram in markdown format. Uses a separate thread for a dispatching. Support many chats. Support big messages (over 4096 chars). Support telegram API calls restrictions.

Installation

pip install python-telegram-logger

Quick start

  1. Configure logger with dict config:
config = {
    ...
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "telegram": {
            "class": "python_telegram_logger.Handler",
            "token": "bot_token",
            "chat_ids": [123456789, -1234567891011],

        }
    },
    "loggers": {
        "tg": {
            "level": "INFO",
            "handlers": ["telegram",]
        }
    }
}
  1. Use it!
import logging
logger = logging.getLogger("tg")

logger.info("test")

try:
    raise Exception("raise!")
except Exception:
    logger.exception("catch!")
  1. Formatting:
  • Configure a formatter using dict config, example:
config = {
    ...
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "default": {
            "()": "python_telegram_logger.MarkdownFormatter",
            "fmt": " *%(levelname)s* _%(name)s : %(funcName)s_"
        }
    },
    "handlers": {
        "telegram": {
            "class": "python_telegram_logger.Handler",
            "token": "bot_token",
            "chat_ids": [123456789, -1234567891011],
            "formatter": "default"
        }
    },
    "loggers": {
        "tg": {
            "level": "INFO",
            "handlers": ["telegram",]
        }
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages