Telegram
telegram package
This module contains the TelegramHandler class.
- class TelegramLoggingHandler(bot_token, channel_name, level=0, host='api.telegram.org', protect_content=True, disable_notification=False)[source]
This method is called by the logging framework to write a log message to the telegram channel. https://core.telegram.org/bots/api#sendmessage
Usage:
from bohicalog import logger from bohicalog.handlers.telegram import ( HTMLFormatter, TelegramLoggingHandler, ) BOT_TOKEN = TOKEN" CHANNEL_NAME = "chat id" # if its public you can use the name with an @ infront: '@example' telegram_handler = TelegramLoggingHandler( BOT_TOKEN, CHANNEL_NAME, level=logging.INFO, disable_notification=False ) telegram_handler.setFormatter(HTMLFormatter(use_emoji=True)) logger.addHandler(telegram_handler) logger.info("Telegram test")
- Parameters
bot_token – Token of the telegram bot
channel_name – channel name to write to
level – Logging level
host – host to use
protect_content – disable forwards (default: True)
disable_notification – disable notifications (default: False)
This module contains the buffer class.
- class Buffer(max_size=None)[source]
Buffer class for the telegram handler
Usage:
from bohicalog.handlers.telegram.buffer import Buffer buffer = Buffer(max_size=1000)
- Parameters
max_size – max size of the buffer
Contains constants for the telegram handler.
Formatters for bohicalog.handlers.telegram.
- class TelegramFormatter(fmt=None, *args, **kwargs)[source]
Base formatter class suitable for use with TelegramHandler
- Parameters
fmt – format string
args – positional arguments
kwargs – keyword arguments
- class MarkdownFormatter(fmt=None, *args, **kwargs)[source]
Markdown formatter for telegram.
- Parameters
fmt – format string
args – positional arguments
kwargs – keyword arguments
- class HTMLFormatter(*args, **kwargs)[source]
HTML formatter for telegram.
- Parameters
args – positional arguments
kwargs – keyword arguments
- format(record)[source]
Format the record.
- Parameters
record (logging.LogRecord) –
Utility functions for telegram handler