1
0
mirror of https://github.com/elisspace/core.git synced 2026-08-29 15:43:55 +00:00

Fix logger creating many thread locks

We call getLogger for each integration to get the current
log level when loading the integrations page. This creates
a storm of threading locks
This commit is contained in:
J. Nick Koston
2023-05-29 18:09:55 -05:00
parent db931132a8
commit aafb55d2f4
2 changed files with 11 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ from collections import defaultdict
from collections.abc import Mapping
import contextlib
from dataclasses import asdict, dataclass
from functools import lru_cache
import logging
from typing import Any, cast
@@ -216,3 +217,11 @@ class LoggerSettings:
)
return dict(combined_logs)
get_logger = lru_cache(maxsize=256)(logging.getLogger)
"""Get a logger.
getLogger uses a threading.RLock, so we cache the result to avoid
locking the threads every time the integrations page is loaded.
"""

View File

@@ -1,5 +1,4 @@
"""Websocket API handlers for the logger integration."""
import logging
from typing import Any
import voluptuous as vol
@@ -16,6 +15,7 @@ from .helpers import (
LogPersistance,
LogSettingsType,
async_get_domain_config,
get_logger,
)
@@ -38,7 +38,7 @@ def handle_integration_log_info(
[
{
"domain": integration,
"level": logging.getLogger(
"level": get_logger(
f"homeassistant.components.{integration}"
).getEffectiveLevel(),
}