Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Adding username parameter #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion telegram_handler/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class TelegramHandler(logging.Handler):
API_ENDPOINT = 'https://api.telegram.org'
last_response = None

def __init__(self, token, chat_id=None, level=logging.NOTSET, timeout=2, disable_notification=False,
def __init__(self, token, chat_id=None, username=None, level=logging.NOTSET, timeout=2, disable_notification=False,
disable_web_page_preview=False, proxies=None):
self.token = token
self.username = username
self.disable_web_page_preview = disable_web_page_preview
self.disable_notification = disable_notification
self.timeout = timeout
Expand Down Expand Up @@ -82,6 +83,8 @@ def send_document(self, text, document, **kwargs):

def emit(self, record):
text = self.format(record)
if self.username is not None:
text = '<b>{}</b>: {}'.format(self.username, text)

data = {
'chat_id': self.chat_id,
Expand Down