-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cythonize _debug and _loggable mixins (#392)
* feat: cythonize _debug and _loggable mixins * chore: `black .` --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5ce4e02
commit 41dd0ea
Showing
4 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import abc | ||
from a_sync.primitives._loggable import _LoggerMixin | ||
|
||
class _DebugDaemonMixin(_LoggerMixin, metaclass=abc.ABCMeta): | ||
""" | ||
A mixin class that provides a framework for debugging capabilities using a daemon task. | ||
This mixin sets up the structure for managing a debug daemon task. Subclasses are responsible for implementing the specific behavior of the daemon, including any logging functionality. | ||
See Also: | ||
:class:`_LoggerMixin` for logging capabilities. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from functools import cached_property as cached_property | ||
from logging import Logger | ||
|
||
class _LoggerMixin: | ||
""" | ||
A mixin class that adds logging capabilities to other classes. | ||
This mixin provides a cached property for accessing a logger instance and a property to check if debug logging is enabled. | ||
See Also: | ||
- :func:`logging.getLogger` | ||
- :class:`logging.Logger` | ||
""" | ||
|
||
@cached_property | ||
def logger(self) -> Logger: | ||
""" | ||
Provides a logger instance specific to the class using this mixin. | ||
The logger ID is constructed from the module and class name, and optionally includes an instance name if available. | ||
Examples: | ||
>>> class MyClass(_LoggerMixin): | ||
... _name = "example" | ||
... | ||
>>> instance = MyClass() | ||
>>> logger = instance.logger | ||
>>> logger.name | ||
\'module_name.MyClass.example\' | ||
>>> class AnotherClass(_LoggerMixin): | ||
... pass | ||
... | ||
>>> another_instance = AnotherClass() | ||
>>> another_logger = another_instance.logger | ||
>>> another_logger.name | ||
\'module_name.AnotherClass\' | ||
Note: | ||
Replace `module_name` with the actual module name where the class is defined. | ||
See Also: | ||
- :func:`logging.getLogger` | ||
- :class:`logging.Logger` | ||
""" | ||
|
||
@property | ||
def debug_logs_enabled(self) -> bool: | ||
""" | ||
Checks if debug logging is enabled for the logger. | ||
Examples: | ||
>>> class MyClass(_LoggerMixin): | ||
... pass | ||
... | ||
>>> instance = MyClass() | ||
>>> instance.debug_logs_enabled | ||
False | ||
See Also: | ||
- :attr:`logging.Logger.isEnabledFor` | ||
""" |
File renamed without changes.