Simple telegram logger
Project description
=====
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",]
}
}
}
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",]
}
}
}
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
Close
Hashes for python-telegram-logger-1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0242609fc5534338b2076a950a4033acf6c919a1b851077472814fa9a97e7d58 |
|
MD5 | 3afbe23052cbf2b7d3a100766b4c0fcd |
|
BLAKE2b-256 | f999ea559e9a155696b1733e339e2da90960351e3694895f512ed145cc2f4d58 |