From cad325c87496eb116f79a438413cbcbbbf30f599 Mon Sep 17 00:00:00 2001 From: leandrotoledo Date: Mon, 20 Jul 2015 08:36:08 -0300 Subject: [PATCH] Adding logging --- telegram/bot.py | 26 ++++++++++++-------------- tests/test_bot.py | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 9cd4be879..6aa6874a6 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -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} diff --git a/tests/test_bot.py b/tests/test_bot.py index 28339ab75..d65a901f8 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -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')