diff --git a/daft/logging.py b/daft/logging.py index 36bd6aa903..279449e97c 100644 --- a/daft/logging.py +++ b/daft/logging.py @@ -1,6 +1,7 @@ from __future__ import annotations import sys +from logging import LogRecord def setup_logger() -> None: @@ -15,6 +16,10 @@ def setup_logger() -> None: logger.add(sys.stderr, level=LOGURU_LEVEL) class InterceptHandler(logging.Handler): + def filter(self, record: LogRecord) -> bool: + parent = super().filter(record) + return parent or record.pathname.startswith("src/") + def emit(self, record: logging.LogRecord) -> None: # Get corresponding Loguru level if it exists. level: str | int @@ -31,10 +36,5 @@ def emit(self, record: logging.LogRecord) -> None: logger.opt(depth=depth - 1, exception=record.exc_info).log(level, record.getMessage()) - # Clear out any existing standard loggers. - root = logging.root - for h in root.handlers[:]: - root.removeHandler(h) - h.close() - # Add handler that redirects logs to loguru. - logging.basicConfig(handlers=[InterceptHandler()], level=0) + logging.getLogger().setLevel(logger.level(LOGURU_LEVEL).no) + logging.getLogger().addHandler(InterceptHandler())