mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
Reduce log verbosity during bias tester runs
This commit is contained in:
@@ -144,5 +144,3 @@ def start_lookahead_analysis(args: Dict[str, Any]) -> None:
|
||||
|
||||
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
||||
LookaheadAnalysisSubFunctions.start(config)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def set_loggers(verbosity: int = 0, api_verbosity: str = 'info') -> None:
|
||||
"""
|
||||
Set the logging level for third party libraries
|
||||
@@ -23,3 +26,29 @@ def set_loggers(verbosity: int = 0, api_verbosity: str = 'info') -> None:
|
||||
logging.getLogger('werkzeug').setLevel(
|
||||
logging.ERROR if api_verbosity == 'error' else logging.INFO
|
||||
)
|
||||
|
||||
|
||||
__BIAS_TESTER_LOGGERS = [
|
||||
'freqtrade.resolvers',
|
||||
'freqtrade.strategy.hyper',
|
||||
]
|
||||
|
||||
|
||||
def reduce_verbosity_for_bias_tester() -> None:
|
||||
"""
|
||||
Reduce verbosity for bias tester.
|
||||
It loads the same strategy several times, which would spam the log.
|
||||
"""
|
||||
logger.info("Reducing verbosity for bias tester.")
|
||||
for logger_name in __BIAS_TESTER_LOGGERS:
|
||||
logging.getLogger(logger_name).setLevel(logging.WARNING)
|
||||
|
||||
|
||||
def restore_verbosity_for_bias_tester() -> None:
|
||||
"""
|
||||
Restore verbosity after bias tester.
|
||||
"""
|
||||
logger.info("Restoring log verbosity.")
|
||||
log_level = logging.getLogger('freqtrade').getEffectiveLevel()
|
||||
for logger_name in __BIAS_TESTER_LOGGERS:
|
||||
logging.getLogger(logger_name).setLevel(log_level)
|
||||
|
||||
@@ -11,6 +11,8 @@ import pandas as pd
|
||||
from freqtrade.configuration import TimeRange
|
||||
from freqtrade.data.history import get_timerange
|
||||
from freqtrade.exchange import timeframe_to_minutes
|
||||
from freqtrade.loggers.set_log_levels import (reduce_verbosity_for_bias_tester,
|
||||
restore_verbosity_for_bias_tester)
|
||||
from freqtrade.optimize.backtesting import Backtesting
|
||||
|
||||
|
||||
@@ -231,6 +233,8 @@ class LookaheadAnalysis:
|
||||
# first make a single backtest
|
||||
self.fill_full_varholder()
|
||||
|
||||
reduce_verbosity_for_bias_tester()
|
||||
|
||||
# check if requirements have been met of full_varholder
|
||||
found_signals: int = self.full_varHolder.result['results'].shape[0] + 1
|
||||
if found_signals >= self.targeted_trade_amount:
|
||||
@@ -251,6 +255,8 @@ class LookaheadAnalysis:
|
||||
break
|
||||
self.analyze_row(idx, result_row)
|
||||
|
||||
# Restore verbosity, so it's not too quiet for the next strategy
|
||||
restore_verbosity_for_bias_tester()
|
||||
# check and report signals
|
||||
if self.current_analysis.total_signals < self.local_config['minimum_trade_amount']:
|
||||
logger.info(f" -> {self.local_config['strategy']} : too few trades. "
|
||||
|
||||
@@ -7,6 +7,8 @@ import pytest
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.loggers import (FTBufferingHandler, FTStdErrStreamHandler, set_loggers,
|
||||
setup_logging, setup_logging_pre)
|
||||
from freqtrade.loggers.set_log_levels import (reduce_verbosity_for_bias_tester,
|
||||
restore_verbosity_for_bias_tester)
|
||||
|
||||
|
||||
def test_set_loggers() -> None:
|
||||
@@ -128,3 +130,19 @@ def test_set_loggers_journald_importerror(import_fails):
|
||||
match=r'You need the cysystemd python package.*'):
|
||||
setup_logging(config)
|
||||
logger.handlers = orig_handlers
|
||||
|
||||
|
||||
def test_reduce_verbosity():
|
||||
reduce_verbosity_for_bias_tester()
|
||||
|
||||
assert logging.getLogger('freqtrade.resolvers').level is logging.WARNING
|
||||
assert logging.getLogger('freqtrade.strategy.hyper').level is logging.WARNING
|
||||
# base level wasn't changed
|
||||
assert logging.getLogger('freqtrade').level is logging.INFO
|
||||
|
||||
restore_verbosity_for_bias_tester()
|
||||
|
||||
assert logging.getLogger('freqtrade.resolvers').level is logging.INFO
|
||||
assert logging.getLogger('freqtrade.strategy.hyper').level is logging.INFO
|
||||
assert logging.getLogger('freqtrade').level is logging.INFO
|
||||
# base level wasn't changed
|
||||
|
||||
Reference in New Issue
Block a user