Show only selected warnings using the force_show parameter

This commit is contained in:
mrpabloyeah
2025-04-13 13:06:35 +02:00
parent 33105a996e
commit 16378d32d7
2 changed files with 14 additions and 13 deletions

View File

@@ -20,21 +20,23 @@ class LoggingMixin:
self.refresh_period = refresh_period
self._log_cache: TTLCache = TTLCache(maxsize=1024, ttl=self.refresh_period)
def log_once(self, message: str, logmethod: Callable) -> None:
def log_once(self, message: str, logmethod: Callable, force_show: bool = False) -> None:
"""
Logs message - not more often than "refresh_period" to avoid log spamming
Logs the log-message as debug as well to simplify debugging.
:param message: String containing the message to be sent to the function.
:param logmethod: Function that'll be called. Most likely `logger.info`.
:param force_show: If True, sends the message regardless of show_output value.
:return: None.
"""
@cached(cache=self._log_cache)
def _log_once(message: str):
logmethod(message)
# Log as debug first
self.logger.debug(message)
# Call hidden function.
if self.show_output:
# Call hidden function if show_output is True or force_show is True
if self.show_output or force_show:
_log_once(message)

View File

@@ -237,11 +237,6 @@ class IPairList(LoggingMixin, ABC):
:return: the list of pairs the user wants to trade without those unavailable or
black_listed
"""
# Save show_output value and set it to True
prev_show_output = self.show_output
self.show_output = True
markets = self._exchange.markets
if not markets:
raise OperationalException(
@@ -256,6 +251,7 @@ class IPairList(LoggingMixin, ABC):
f"Pair {pair} is not compatible with exchange "
f"{self._exchange.name}. Removing it from whitelist..",
logger.warning,
True,
)
continue
@@ -263,6 +259,7 @@ class IPairList(LoggingMixin, ABC):
self.log_once(
f"Pair {pair} is not tradable with Freqtrade. Removing it from whitelist..",
logger.warning,
True,
)
continue
@@ -271,19 +268,21 @@ class IPairList(LoggingMixin, ABC):
f"Pair {pair} is not compatible with your stake currency "
f"{self._config['stake_currency']}. Removing it from whitelist..",
logger.warning,
True,
)
continue
# Check if market is active
market = markets[pair]
if not market_is_active(market):
self.log_once(f"Ignoring {pair} from whitelist. Market is not active.", logger.info)
self.log_once(
f"Ignoring {pair} from whitelist. Market is not active.",
logger.info,
True,
)
continue
if pair not in sanitized_whitelist:
sanitized_whitelist.append(pair)
# Return show_output to its previous value
self.show_output = prev_show_output
# We need to remove pairs that are unknown
return sanitized_whitelist