From 4dd1e8d6dc4dc2b698ef1320955e2d20e4144da9 Mon Sep 17 00:00:00 2001 From: Sammy Sidhu Date: Fri, 6 Oct 2023 14:56:53 -0700 Subject: [PATCH] [BUG] Don't remove all handles and Only use handler for files in `src/` (#1473) --- daft/logging.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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())