mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
Adding logging
This commit is contained in:
parent
b6fb2bc6bf
commit
cad325c874
2 changed files with 13 additions and 15 deletions
|
@ -18,7 +18,8 @@ import logging
|
|||
from telegram import (User, Message, Update, UserProfilePhotos, TelegramError,
|
||||
ReplyMarkup, InputFile, TelegramObject)
|
||||
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
|
||||
class Bot(TelegramObject):
|
||||
|
@ -26,13 +27,7 @@ class Bot(TelegramObject):
|
|||
def __init__(self,
|
||||
token,
|
||||
base_url=None,
|
||||
debug=True):
|
||||
self.log = logging.getLogger(__name__)
|
||||
if debug:
|
||||
self.log.setLevel(logging.DEBUG)
|
||||
else:
|
||||
self.log.setLevel(logging.INFO)
|
||||
|
||||
debug=False):
|
||||
self.token = token
|
||||
|
||||
if base_url is None:
|
||||
|
@ -40,6 +35,12 @@ class Bot(TelegramObject):
|
|||
else:
|
||||
self.base_url = base_url + self.token
|
||||
|
||||
self.log = logging.getLogger(__name__)
|
||||
if debug:
|
||||
self.log.setLevel(logging.DEBUG)
|
||||
else:
|
||||
self.log.setLevel(logging.INFO)
|
||||
|
||||
try:
|
||||
bot = self.getMe()
|
||||
|
||||
|
@ -61,10 +62,10 @@ class Bot(TelegramObject):
|
|||
|
||||
@functools.wraps(func)
|
||||
def decorator(self, *args, **kwargs):
|
||||
logger.debug('Entering %s' % func.__name__)
|
||||
logger.debug('Entering: %s' % func.__name__)
|
||||
result = func(self, *args, **kwargs)
|
||||
logger.debug(result)
|
||||
logger.debug('Exiting %s' % func.__name__)
|
||||
logger.debug('Exiting: %s' % func.__name__)
|
||||
return result
|
||||
return decorator
|
||||
|
||||
|
@ -106,7 +107,6 @@ class Bot(TelegramObject):
|
|||
return func(self, *args, **kwargs)
|
||||
return decorator
|
||||
|
||||
|
||||
@log
|
||||
@require_authentication
|
||||
def clearCredentials(self):
|
||||
|
@ -562,7 +562,6 @@ class Bot(TelegramObject):
|
|||
|
||||
return True
|
||||
|
||||
@log
|
||||
def _requestUrl(self,
|
||||
url,
|
||||
method,
|
||||
|
@ -613,7 +612,6 @@ class Bot(TelegramObject):
|
|||
|
||||
return 0 # if not a POST or GET request
|
||||
|
||||
@log
|
||||
def _parseAndCheckTelegram(self,
|
||||
json_data):
|
||||
"""Try and parse the JSON returned from Telegram and return an empty
|
||||
|
@ -638,7 +636,7 @@ class Bot(TelegramObject):
|
|||
|
||||
return data['result']
|
||||
|
||||
def to_data(self):
|
||||
def to_dict(self):
|
||||
data = {'id': self.id,
|
||||
'username': self.username,
|
||||
'first_name': self.username}
|
||||
|
|
|
@ -7,7 +7,7 @@ import unittest
|
|||
|
||||
class BotTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
bot = telegram.Bot(token=os.environ.get('TOKEN'))
|
||||
bot = telegram.Bot(token=os.environ.get('TOKEN'), debug=True)
|
||||
self._bot = bot
|
||||
print('Testing the Bot API class')
|
||||
|
||||
|
|
Loading…
Reference in a new issue