In a class with several static functions, I usually write the following messages:
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 did 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 can do this, but it looks 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 template for registering from static methods?
source share