1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Add logger.

This commit is contained in:
eternnoir 2015-07-20 09:56:17 +08:00
parent 968d30e246
commit 99b82b6219
2 changed files with 12 additions and 6 deletions

View File

@ -9,6 +9,8 @@ except ImportError:
import queue as Queue
import time
import logging
logger = logging.getLogger('Telebot')
import re
from telebot import apihelper, types
@ -83,7 +85,7 @@ class TeleBot:
:param token: bot API token
:param create_threads: Create thread for message handler
:param num_threads: Number of worker in thread pool.
:return:
:return: Telebot object.
"""
self.token = token
self.update_listener = []
@ -110,7 +112,7 @@ class TeleBot:
self.last_update_id = update['update_id']
msg = types.Message.de_json(update['message'])
new_messages.append(msg)
logger.debug('GET %d new messages' % len(new_messages))
if len(new_messages) > 0:
self.process_new_messages(new_messages)
@ -145,17 +147,17 @@ class TeleBot:
self.polling_thread.start()
def __polling(self, none_stop, interval):
print('TeleBot: Started polling.')
logger.info('TeleBot: Started polling.')
while not self.__stop_polling.wait(interval):
try:
self.get_update()
except Exception as e:
if not none_stop:
self.__stop_polling.set()
print("TeleBot: Exception occurred. Stopping.")
print(e)
logger.info("TeleBot: Exception occurred. Stopping.")
logger.error(e.message)
print('TeleBot: Stopped polling.')
logger.info('TeleBot: Stopped polling.')
def stop_polling(self):
self.__stop_polling.set()
@ -471,3 +473,4 @@ class AsyncTeleBot(TeleBot):
@async()
def send_chat_action(self, *args, **kwargs):
return TeleBot.send_chat_action(self, *args, **kwargs)

View File

@ -5,6 +5,8 @@ from six import string_types
import telebot
from telebot import types
logger = telebot.logger
def _make_request(token, method_name, method='get', params=None, files=None):
"""
@ -18,6 +20,7 @@ def _make_request(token, method_name, method='get', params=None, files=None):
"""
request_url = telebot.API_URL + 'bot' + token + '/' + method_name
result = requests.request(method, request_url, params=params, files=files)
logger.debug(result.text)
if result.status_code != 200:
raise ApiException(method_name, result)
try: