diff --git a/redisvl/utils/log.py b/redisvl/utils/log.py index b82b3ecc..b78c2094 100644 --- a/redisvl/utils/log.py +++ b/redisvl/utils/log.py @@ -1,5 +1,4 @@ import logging -import sys def get_logger(name, log_level="info", fmt=None): @@ -10,13 +9,7 @@ def get_logger(name, log_level="info", fmt=None): logger = logging.getLogger(name) - # Only configure this specific logger, not the root logger - # Check if the logger already has handlers to respect existing configuration + # Add a NullHandler to loggers to avoid "no handler found" warnings if not logger.handlers: - logging.basicConfig( - level=logging.INFO, - format="%(asctime)s %(name)s %(levelname)s %(message)s", - datefmt="%H:%M:%S", - stream=sys.stdout, - ) + logger.addHandler(logging.NullHandler()) return logger diff --git a/tests/unit/logger_interference_checker.py b/tests/unit/logger_interference_checker.py index 7d1c9ca9..04ad3815 100644 --- a/tests/unit/logger_interference_checker.py +++ b/tests/unit/logger_interference_checker.py @@ -9,13 +9,10 @@ ) ) -# Configure root logger -root_logger = logging.getLogger() -root_logger.handlers = [handler] -root_logger.setLevel(logging.INFO) - # Log before import app_logger = logging.getLogger("app") +app_logger.setLevel(logging.INFO) +app_logger.addHandler(handler) app_logger.info("PRE_IMPORT_FORMAT") # Import RedisVL diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index d9770f14..85a23c72 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -489,18 +489,22 @@ def test_logging_configuration_not_overridden(self): # Extract the log lines output_lines = result.stdout.strip().split("\n") - pre_import_line = "" - post_import_line = "" + pre_import_lines = [] + post_import_lines = [] for line in output_lines: if "PRE_IMPORT_FORMAT" in line: - pre_import_line = line + pre_import_lines.append(line) elif "POST_IMPORT_FORMAT" in line: - post_import_line = line + post_import_lines.append(line) # Check if we found both lines - assert pre_import_line, "No pre-import log message found" - assert post_import_line, "No post-import log message found" + assert pre_import_lines, "No pre-import log message(s) found" + assert post_import_lines, "No post-import log message(s) found" + assert len(pre_import_lines) == 1, "Multiple pre-import log messages found" + assert len(post_import_lines) == 1, "Multiple post-import log messages found" + pre_import_line = pre_import_lines[0] + post_import_line = post_import_lines[0] # Print for debugging print(f"Pre-import format: {pre_import_line}")