Skip to content

Commit

Permalink
dont drop standard handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
samster25 committed Oct 6, 2023
1 parent cdbcec4 commit f13e9c1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions daft/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations
from logging import LogRecord

import sys


def setup_logger() -> None:
import inspect
import logging

from loguru import logger
from loguru._defaults import env

Expand All @@ -15,6 +15,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 +35,6 @@ 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 f13e9c1

Please sign in to comment.