Skip to content

Commit d992f8f

Browse files
authored
Avoid configuring root logger in RedisVL (#445)
Closes #443 This PR updates the logger configuration helper for RedisVL to avoid configuring the root logger via `logging.basicConfig`. That operation was interfering with user-configured loggers, causing app logs to be emitted multiple times and making it trickier to hide RedisVL logs when running in production. In its place, we now configure a `NullHandler` (mainly to avoid issues with loggers not having any handlers configured). **This means that any RedisVL usage that expects logs to have a specific format must now configure that format for itself.**
1 parent 595c450 commit d992f8f

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

redisvl/utils/log.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import sys
32

43

54
def get_logger(name, log_level="info", fmt=None):
@@ -10,13 +9,7 @@ def get_logger(name, log_level="info", fmt=None):
109

1110
logger = logging.getLogger(name)
1211

13-
# Only configure this specific logger, not the root logger
14-
# Check if the logger already has handlers to respect existing configuration
12+
# Add a NullHandler to loggers to avoid "no handler found" warnings
1513
if not logger.handlers:
16-
logging.basicConfig(
17-
level=logging.INFO,
18-
format="%(asctime)s %(name)s %(levelname)s %(message)s",
19-
datefmt="%H:%M:%S",
20-
stream=sys.stdout,
21-
)
14+
logger.addHandler(logging.NullHandler())
2215
return logger

tests/unit/logger_interference_checker.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
)
1010
)
1111

12-
# Configure root logger
13-
root_logger = logging.getLogger()
14-
root_logger.handlers = [handler]
15-
root_logger.setLevel(logging.INFO)
16-
1712
# Log before import
1813
app_logger = logging.getLogger("app")
14+
app_logger.setLevel(logging.INFO)
15+
app_logger.addHandler(handler)
1916
app_logger.info("PRE_IMPORT_FORMAT")
2017

2118
# Import RedisVL

tests/unit/test_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,18 +489,22 @@ def test_logging_configuration_not_overridden(self):
489489

490490
# Extract the log lines
491491
output_lines = result.stdout.strip().split("\n")
492-
pre_import_line = ""
493-
post_import_line = ""
492+
pre_import_lines = []
493+
post_import_lines = []
494494

495495
for line in output_lines:
496496
if "PRE_IMPORT_FORMAT" in line:
497-
pre_import_line = line
497+
pre_import_lines.append(line)
498498
elif "POST_IMPORT_FORMAT" in line:
499-
post_import_line = line
499+
post_import_lines.append(line)
500500

501501
# Check if we found both lines
502-
assert pre_import_line, "No pre-import log message found"
503-
assert post_import_line, "No post-import log message found"
502+
assert pre_import_lines, "No pre-import log message(s) found"
503+
assert post_import_lines, "No post-import log message(s) found"
504+
assert len(pre_import_lines) == 1, "Multiple pre-import log messages found"
505+
assert len(post_import_lines) == 1, "Multiple post-import log messages found"
506+
pre_import_line = pre_import_lines[0]
507+
post_import_line = post_import_lines[0]
504508

505509
# Print for debugging
506510
print(f"Pre-import format: {pre_import_line}")

0 commit comments

Comments
 (0)