Coverage for src / lexigram / contracts / core / logging.py: 0%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-15 18:57 +0800

1"""Logging protocols for Lexigram Framework. 

2 

3This module defines the standard logging interface used across the 

4framework to avoid circular dependencies and allow sub-packages to 

5remain independent of the concrete logging implementation. 

6""" 

7 

8from __future__ import annotations 

9 

10from typing import Any, Protocol, runtime_checkable 

11 

12 

13@runtime_checkable 

14class LoggerProtocol(Protocol): 

15 """Protocol for structured logging with context support.""" 

16 

17 def debug(self, msg: str, *args: Any, **kwargs: Any) -> None: ... 

18 def info(self, msg: str, *args: Any, **kwargs: Any) -> None: ... 

19 def warning(self, msg: str, *args: Any, **kwargs: Any) -> None: ... 

20 def error(self, msg: str, *args: Any, **kwargs: Any) -> None: ... 

21 def critical(self, msg: str, *args: Any, **kwargs: Any) -> None: ... 

22 def exception(self, msg: str, *args: Any, **kwargs: Any) -> None: ... 

23 

24 def bind(self, **kwargs: Any) -> LoggerProtocol: 

25 """Add context variables to the logger.""" 

26 ... 

27 

28 def unbind(self, *keys: str) -> LoggerProtocol: 

29 """Remove context variables from the logger.""" 

30 ... 

31 

32 

33@runtime_checkable 

34class LoggerFactoryProtocol(Protocol): 

35 """Protocol for creating/retrieving named logger instances.""" 

36 

37 def get_logger(self, name: str | None = None) -> LoggerProtocol: 

38 """Get a logger instance for the given name.""" 

39 ... 

40 

41 

42@runtime_checkable 

43class RedactorProtocol(Protocol): 

44 """Protocol for sensitive data redaction.""" 

45 

46 def redact_dict(self, data: dict[str, Any]) -> dict[str, Any]: 

47 """Return a copy of ``data`` with sensitive values masked.""" 

48 ... 

49 

50 def redact_value(self, value: Any) -> Any: 

51 """Redact a single value if it matches a sensitive pattern.""" 

52 ... 

53 

54 

55__all__ = ["LoggerFactoryProtocol", "LoggerProtocol", "RedactorProtocol"]