In a class with few no static functions, I typically do logging like this:
class ClassA:
def __init__(self):
self._logger = logging.getLogger(self.__class__.__name__)
def do_something(self):
self._logger.info("Doing something")
def do_something_else(self):
self._logger.info("Doing something else.")
In a class with static methods I've been doing this:
class ClassB:
_logger = logging.getLogger("ClassB")
@staticmethod
def do_something():
ClassB._logger.info("Doing something")
@staticmethod
def do_something_else():
ClassB._logger.info("Doing something else")
You could do this but it seems lame:
class ClassB:
@staticmethod
def do_something():
logger = logging.getLogger("ClassB")
logger.info("Doing something")
@staticmethod
def do_something_else():
logger = logging.getLogger("ClassB")
logger.info("Doing something else")
Is there a better pattern for logging from static methods?