diff --git a/core/utils.py b/core/utils.py index 1dabf3a6..d26b0dd3 100644 --- a/core/utils.py +++ b/core/utils.py @@ -254,7 +254,10 @@ def cleanup_memory(log_usage=True, force_collection=True): log_usage: Whether to log memory usage before and after cleanup force_collection: Whether to force garbage collection """ - logger.debug("Starting memory cleanup django memory cleanup") + logger.trace("Starting memory cleanup django memory cleanup") + # Skip logging if log level is not set to debug (no reason to run memory usage if we don't log it) + if not logger.isEnabledFor(logging.DEBUG): + log_usage = False if log_usage: try: import psutil @@ -283,4 +286,4 @@ def cleanup_memory(log_usage=True, force_collection=True): logger.debug(f"Memory after cleanup: {after_mem:.2f} MB (change: {after_mem-before_mem:.2f} MB)") except (ImportError, Exception): pass - logger.debug("Memory cleanup complete for django") + logger.trace("Memory cleanup complete for django")