-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
As discussed earlier, here's the code snippet I was talking about to make logging easier project-wide:
# logger.py
import logging
class LogMixin:
"""
Use this mixin to do logging:
self.logger.debug("My debugging message")
"""
__logger = None
@property
def logger(self) -> logging.Logger:
if self.__logger:
return self.__logger
self.__logger = logging.getLogger(self.__class__.__module__)
return self.loggerTo use it, just do this:
from logger import LogMixin
class MyClass(LogMixin, AnyOtherParent):
...
def my_method(self):
self.logger.debug("This is my debug message with %s", some_variable)This will produce log entries attached to the class and file path rather than the root.
cgmcintyr
Metadata
Metadata
Assignees
Labels
No labels