I want to do logging in objects & classes which are spread over several modules.
Usually, I'm checking in the constructor of a class if there is an exisiting (root) logger instance and pass it then into the object.
import logging
from logging import config
class TestClass(object):
def __init__(self, logger=None):
self.logger = logger or logging.getLogger(self.__class__.__name__)
def bar(self):
self.logger.info("Hi, Bar")
but how do I make this logger available for my utility class which contains only ClassMethods / Staticmethods?
I'm looking for smth like this:
class TestClass(object):
def __init__(cls, logger=None):
cls.logger = logger or logging.getLogger(cls.__class__.__name__)
@classmethod
def foo(cls):
cls.logger.info("Hi, Foo")
I know that the code above doesn't work, but I hope it makes clear what I'm looking for.
Any idea / best practices are appreciated!