diff --git a/freqtrade/loggers.py b/freqtrade/loggers.py index c4a1af4f3..6e66abeeb 100644 --- a/freqtrade/loggers.py +++ b/freqtrade/loggers.py @@ -1,5 +1,4 @@ import logging -import queue import sys from logging import Formatter from logging.handlers import (BufferingHandler, RotatingFileHandler, @@ -9,7 +8,6 @@ from typing import Any, Dict from freqtrade.exceptions import OperationalException logger = logging.getLogger(__name__) -log_queue = queue.Queue(-1) LOGFORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' # Initialize bufferhandler - will be used for /log endpoints @@ -41,9 +39,10 @@ def _set_loggers(verbosity: int = 0, api_verbosity: str = 'info') -> None: def setup_logging_pre() -> None: """ - Setup early logging. - This uses a queuehandler, which delays logging. - # TODO: How does QueueHandler work if no listenerhandler is attached?? + Early setup for logging. + Uses INFO loglevel and only the Streamhandler. + Early messages (before proper logging setup) will therefore only be available + after the proper logging setup. """ logging.basicConfig( level=logging.INFO, diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 2fb1e3ec1..1dd0ecff8 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -447,6 +447,14 @@ def test_api_logs(botclient): assert isinstance(rc.json['logs'][0][3], str) assert isinstance(rc.json['logs'][0][4], str) + rc = client_get(client, f"{BASE_URI}/logs?limit=5") + assert_response(rc) + assert len(rc.json) == 2 + assert 'logs' in rc.json + # Using a fixed comparison here would make this test fail! + assert rc.json['log_count'] == 5 + assert len(rc.json['logs']) == rc.json['log_count'] + def test_api_edge_disabled(botclient, mocker, ticker, fee, markets): ftbot, client = botclient diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 1144d8279..e0df31437 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1127,6 +1127,21 @@ def test_telegram_logs(default_conf, update, mocker) -> None: 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] + msg_mock.reset_mock() + context.args = ["1"] + telegram._logs(update=update, context=context) + assert msg_mock.call_count == 1 + + msg_mock.reset_mock() + # Test with changed MaxMessageLength + mocker.patch('freqtrade.rpc.telegram.MAX_TELEGRAM_MESSAGE_LENGTH', 200) + context = MagicMock() + context.args = [] + telegram._logs(update=update, context=context) + # Called at least 3 times. Exact times will change with unrelated changes to setup messages + # Therefore we don't test for this explicitly. + assert msg_mock.call_count > 3 + def test_edge_disabled(default_conf, update, mocker) -> None: msg_mock = MagicMock()