Open vgiotsas opened 6 years ago
I have a handy code snippet that I use these days to keep logging easy. Maybe this would help?
import logging
class LogMixin(object):
"""
Use this mixin to do logging:
self.logger.debug("My debugging message")
"""
_logger = None
@property
def logger(self):
if self._logger:
return self._logger
self._logger = logging.getLogger(self.__class__.__module__)
return self.logger
Currently (v. 1.2.1) all the warnings are logged using the root logger which isn't very helpful since the logging messages do not identify which module emitted the warning message, which is especially problematic when using sagan in scripts that include other libraries that also don't use named loggers.
For libraries, the best practice for logging is to use Loggers with name
__name__
to ensure no name collisions.