use native python logger

This commit is contained in:
gcarq
2018-03-25 21:37:14 +02:00
parent 3f8d7dae39
commit fa7f74b4bc
14 changed files with 142 additions and 152 deletions

View File

@@ -3,7 +3,7 @@
"""
This module manage Telegram communication
"""
import logging
from typing import Any, Callable
from tabulate import tabulate
@@ -15,6 +15,9 @@ from freqtrade.__init__ import __version__
from freqtrade.rpc.rpc import RPC
logger = logging.getLogger(__name__)
def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[..., Any]:
"""
Decorator to check if the message comes from the correct chat_id
@@ -31,13 +34,13 @@ def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[
chat_id = int(self._config['telegram']['chat_id'])
if int(update.message.chat_id) != chat_id:
self.logger.info(
logger.info(
'Rejected unauthorized message from: %s',
update.message.chat_id
)
return wrapper
self.logger.info(
logger.info(
'Executing handler: %s for chat_id: %s',
command_handler.__name__,
chat_id
@@ -45,7 +48,7 @@ def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[
try:
return command_handler(self, *args, **kwargs)
except BaseException:
self.logger.exception('Exception occurred within Telegram module')
logger.exception('Exception occurred within Telegram module')
return wrapper
@@ -101,7 +104,7 @@ class Telegram(RPC):
timeout=30,
read_latency=60,
)
self.logger.info(
logger.info(
'rpc.telegram is listening for following commands: %s',
[h.command for h in handles]
)
@@ -357,7 +360,7 @@ class Telegram(RPC):
'max': [self._config['max_open_trades']]
}, headers=['current', 'max'], tablefmt='simple')
message = "<pre>{}</pre>".format(message)
self.logger.debug(message)
logger.debug(message)
self.send_msg(message, parse_mode=ParseMode.HTML)
@authorized_only
@@ -428,7 +431,7 @@ class Telegram(RPC):
except NetworkError as network_err:
# Sometimes the telegram server resets the current connection,
# if this is the case we send the message again.
self.logger.warning(
logger.warning(
'Telegram NetworkError: %s! Trying one more time.',
network_err.message
)
@@ -439,7 +442,7 @@ class Telegram(RPC):
reply_markup=reply_markup
)
except TelegramError as telegram_err:
self.logger.warning(
logger.warning(
'TelegramError: %s! Giving up on that message.',
telegram_err.message
)