|  | 
| 6 | 6 | import logging | 
| 7 | 7 | from collections.abc import Mapping | 
| 8 | 8 | from dataclasses import field | 
| 9 |  | -from typing import Annotated, Any, Self, cast | 
|  | 9 | +from typing import Annotated, Any | 
| 10 | 10 | 
 | 
| 11 | 11 | import marshmallow | 
| 12 | 12 | import marshmallow.validate | 
| 13 | 13 | from frequenz.channels import Receiver | 
| 14 |  | -from marshmallow import RAISE | 
| 15 |  | -from marshmallow_dataclass import class_schema, dataclass | 
|  | 14 | +from marshmallow_dataclass import dataclass | 
| 16 | 15 | 
 | 
| 17 | 16 | from frequenz.sdk.actor import Actor | 
| 18 | 17 | 
 | 
|  | 18 | +from ._util import load_config | 
|  | 19 | + | 
| 19 | 20 | _logger = logging.getLogger(__name__) | 
| 20 | 21 | 
 | 
| 21 | 22 | LogLevel = Annotated[ | 
| @@ -69,22 +70,6 @@ class LoggingConfig: | 
| 69 | 70 |     ) | 
| 70 | 71 |     """The list of loggers configurations.""" | 
| 71 | 72 | 
 | 
| 72 |  | -    @classmethod | 
| 73 |  | -    def load(cls, configs: Mapping[str, Any]) -> Self:  # noqa: DOC502 | 
| 74 |  | -        """Load and validate configs from a dictionary. | 
| 75 |  | -
 | 
| 76 |  | -        Args: | 
| 77 |  | -            configs: The configuration to validate. | 
| 78 |  | -
 | 
| 79 |  | -        Returns: | 
| 80 |  | -            The configuration if they are valid. | 
| 81 |  | -
 | 
| 82 |  | -        Raises: | 
| 83 |  | -            ValidationError: if the configuration are invalid. | 
| 84 |  | -        """ | 
| 85 |  | -        schema = class_schema(cls)() | 
| 86 |  | -        return cast(Self, schema.load(configs, unknown=RAISE)) | 
| 87 |  | - | 
| 88 | 73 | 
 | 
| 89 | 74 | class LoggingConfigUpdatingActor(Actor): | 
| 90 | 75 |     """Actor that listens for logging configuration changes and sets them. | 
| @@ -174,7 +159,7 @@ async def _run(self) -> None: | 
| 174 | 159 |         """Listen for configuration changes and update logging.""" | 
| 175 | 160 |         async for message in self._config_recv: | 
| 176 | 161 |             try: | 
| 177 |  | -                new_config = LoggingConfig.load(message) | 
|  | 162 | +                new_config = load_config(LoggingConfig, message) | 
| 178 | 163 |             except marshmallow.ValidationError: | 
| 179 | 164 |                 _logger.exception( | 
| 180 | 165 |                     "Invalid logging configuration received. Skipping config update" | 
|  | 
0 commit comments