File size: 1,207 Bytes
c2b7494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
import sys

_CONFIGURED = False

# Silence noisy third-party libraries (sentence-transformers/httpx/huggingface_hub
# log INFO-level HTTP requests and an "unauthenticated requests" warning on every
# model load) — none of this is actionable for local, cached model usage.
_QUIET_LOGGERS = ("sentence_transformers", "httpx", "huggingface_hub")


def get_logger(name: str) -> logging.Logger:
    global _CONFIGURED
    if not _CONFIGURED:
        logging.basicConfig(
            level=logging.INFO,
            format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
            stream=sys.stdout,
        )
        for quiet_logger in _QUIET_LOGGERS:
            logging.getLogger(quiet_logger).setLevel(logging.ERROR)
        try:
            # huggingface_hub emits its "unauthenticated requests" notice through
            # its own verbosity control rather than a plain logger level, so the
            # logger.setLevel above alone doesn't always suppress it.
            from huggingface_hub.utils import logging as hf_logging

            hf_logging.set_verbosity_error()
        except ImportError:
            pass
        _CONFIGURED = True
    return logging.getLogger(name)