https://github.com/parikls/python-telegram-logger
https://github.com/parikls/python-telegram-logger
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/parikls/python-telegram-logger
- Owner: parikls
- License: bsd-3-clause
- Created: 2018-09-11T20:35:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-15T12:08:14.000Z (over 4 years ago)
- Last Synced: 2025-03-23T19:45:12.386Z (9 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 12
- Watchers: 0
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
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
-----------
.. code-block::
pip install python-telegram-logger
Quick start
-----------
1. Configure logger with dict config:
.. code-block:: python
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",]
}
}
}
2. Use it!
.. code-block:: python
import logging
logger = logging.getLogger("tg")
logger.info("test")
try:
raise Exception("raise!")
except Exception:
logger.exception("catch!")
3. Formatting:
- Configure a formatter using dict config, example:
.. code-block:: python
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",]
}
}
}