Skip to content

Commit 396c59b

Browse files
authored
Cleaned up log verbosity code (#554)
1 parent b046491 commit 396c59b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

paperqa/agents/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
logger = logging.getLogger(__name__)
2020

21-
LOG_VERBOSITY_MAP = {
21+
LOG_VERBOSITY_MAP: dict[int, dict[str, int]] = {
2222
0: {
2323
"paperqa.agents": logging.INFO,
2424
"paperqa.agents.helpers": logging.WARNING,
@@ -28,6 +28,7 @@
2828
"paperqa.agents.search": logging.INFO,
2929
"anthropic": logging.WARNING,
3030
"openai": logging.WARNING,
31+
"httpcore": logging.WARNING,
3132
"httpx": logging.WARNING,
3233
"LiteLLM": logging.WARNING,
3334
"LiteLLM Router": logging.WARNING,
@@ -51,6 +52,7 @@
5152
LOG_VERBOSITY_MAP[3] = LOG_VERBOSITY_MAP[2] | {
5253
"LiteLLM": logging.DEBUG, # <-- every single LLM call
5354
}
55+
_MAX_PRESET_VERBOSITY: int = max(k for k in LOG_VERBOSITY_MAP)
5456

5557
_PAPERQA_PKG_ROOT_LOGGER = logging.getLogger(__name__.split(".", maxsplit=1)[0])
5658
_INITIATED_FROM_CLI = False
@@ -75,12 +77,10 @@ def set_up_rich_handler(install: bool = True) -> RichHandler:
7577

7678

7779
def configure_log_verbosity(verbosity: int = 0) -> None:
78-
max_preset_verbosity: int = max(list(LOG_VERBOSITY_MAP.keys()))
80+
key = min(verbosity, _MAX_PRESET_VERBOSITY)
7981
for logger_name, logger_ in logging.Logger.manager.loggerDict.items():
8082
if isinstance(logger_, logging.Logger) and (
81-
log_level := LOG_VERBOSITY_MAP.get(
82-
min(verbosity, max_preset_verbosity), {}
83-
).get(logger_name)
83+
log_level := LOG_VERBOSITY_MAP.get(key, {}).get(logger_name)
8484
):
8585
logger_.setLevel(log_level)
8686

0 commit comments

Comments
 (0)