Skip to content
Snippets Groups Projects
Unverified Commit e4a15354 authored by J. Nick Koston's avatar J. Nick Koston Committed by GitHub
Browse files

Fix logger creating many thread locks when reloading the integrations page (#93768)

* 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

* fixes
parent d8564eba
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ from collections.abc import Mapping ...@@ -6,6 +6,7 @@ from collections.abc import Mapping
import contextlib import contextlib
from dataclasses import asdict, dataclass from dataclasses import asdict, dataclass
from enum import StrEnum from enum import StrEnum
from functools import lru_cache
import logging import logging
from typing import Any, cast from typing import Any, cast
...@@ -216,3 +217,11 @@ class LoggerSettings: ...@@ -216,3 +217,11 @@ class LoggerSettings:
) )
return dict(combined_logs) 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.
"""
"""Websocket API handlers for the logger integration.""" """Websocket API handlers for the logger integration."""
import logging
from typing import Any from typing import Any
import voluptuous as vol import voluptuous as vol
...@@ -16,6 +15,7 @@ from .helpers import ( ...@@ -16,6 +15,7 @@ from .helpers import (
LogPersistance, LogPersistance,
LogSettingsType, LogSettingsType,
async_get_domain_config, async_get_domain_config,
get_logger,
) )
...@@ -38,7 +38,7 @@ def handle_integration_log_info( ...@@ -38,7 +38,7 @@ def handle_integration_log_info(
[ [
{ {
"domain": integration, "domain": integration,
"level": logging.getLogger( "level": get_logger(
f"homeassistant.components.{integration}" f"homeassistant.components.{integration}"
).getEffectiveLevel(), ).getEffectiveLevel(),
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment