Skip to content

Commit

Permalink
[BUG] Don't remove all handles and Only use handler for files in `src…
Browse files Browse the repository at this point in the history
…/` (#1473)
  • Loading branch information
samster25 authored Oct 6, 2023
1 parent cdbcec4 commit 4dd1e8d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions daft/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
from logging import LogRecord


def setup_logger() -> None:
Expand All @@ -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
Expand All @@ -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())

0 comments on commit 4dd1e8d

Please sign in to comment.