Also provide stacktrace via log endpoints

This commit is contained in:
Matthias 2020-08-15 20:15:02 +02:00
parent f3d4b114bb
commit 56ca37fd8b
3 changed files with 12 additions and 8 deletions

View File

@ -640,7 +640,8 @@ class RPC:
else: else:
buffer = bufferHandler.buffer buffer = bufferHandler.buffer
records = [[datetime.fromtimestamp(r.created).strftime("%Y-%m-%d %H:%M:%S"), records = [[datetime.fromtimestamp(r.created).strftime("%Y-%m-%d %H:%M:%S"),
r.created, r.name, r.levelname, r.message] r.created, r.name, r.levelname,
r.message + ('\n' + r.exc_text if r.exc_text else '')]
for r in buffer] for r in buffer]
return {'log_count': len(records), 'logs': records} return {'log_count': len(records), 'logs': records}

View File

@ -12,6 +12,7 @@ from tabulate import tabulate
from telegram import ParseMode, ReplyKeyboardMarkup, Update from telegram import ParseMode, ReplyKeyboardMarkup, Update
from telegram.error import NetworkError, TelegramError from telegram.error import NetworkError, TelegramError
from telegram.ext import CallbackContext, CommandHandler, Updater from telegram.ext import CallbackContext, CommandHandler, Updater
from telegram.utils.helpers import escape_markdown
from freqtrade.__init__ import __version__ from freqtrade.__init__ import __version__
from freqtrade.rpc import RPC, RPCException, RPCMessageType from freqtrade.rpc import RPC, RPCException, RPCMessageType
@ -651,20 +652,22 @@ class Telegram(RPC):
limit = 10 limit = 10
logs = self._rpc_get_logs(limit)['logs'] logs = self._rpc_get_logs(limit)['logs']
msgs = '' msgs = ''
msg_template = "*{}* {}: {} - `{}`" msg_template = "*{}* {}: {} \\- `{}`"
for logrec in logs: for logrec in logs:
msg = msg_template.format(logrec[0], logrec[2], logrec[3], logrec[4]) msg = msg_template.format(escape_markdown(logrec[0], version=2),
escape_markdown(logrec[2], version=2),
escape_markdown(logrec[3], version=2),
escape_markdown(logrec[4], version=2))
if len(msgs + msg) + 10 >= MAX_TELEGRAM_MESSAGE_LENGTH: if len(msgs + msg) + 10 >= MAX_TELEGRAM_MESSAGE_LENGTH:
# Send message immediately if it would become too long # Send message immediately if it would become too long
self._send_msg(msgs, parse_mode=ParseMode.MARKDOWN) self._send_msg(msgs, parse_mode=ParseMode.MARKDOWN_V2)
msgs = msg + '\n' msgs = msg + '\n'
else: else:
# Append message to messages to send # Append message to messages to send
msgs += msg + '\n' msgs += msg + '\n'
if msgs: if msgs:
self._send_msg(msgs, parse_mode=ParseMode.MARKDOWN) self._send_msg(msgs, parse_mode=ParseMode.MARKDOWN_V2)
except RPCException as e: except RPCException as e:
self._send_msg(str(e)) self._send_msg(str(e))

View File

@ -1124,8 +1124,8 @@ def test_telegram_logs(default_conf, update, mocker) -> None:
context.args = [] context.args = []
telegram._logs(update=update, context=context) telegram._logs(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert "freqtrade.rpc.telegram" in msg_mock.call_args_list[0][0][0] assert "freqtrade\\.rpc\\.telegram" in msg_mock.call_args_list[0][0][0]
assert "freqtrade.resolvers.iresolver" in msg_mock.call_args_list[0][0][0] assert "freqtrade\\.resolvers\\.iresolver" in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock() msg_mock.reset_mock()
context.args = ["1"] context.args = ["1"]