[docs]definit_logger(name,level,printout=True):""" Initialize app logger to configure its level/handler/formatter/etc.. Arguments: name (str): Logger name used to instanciate and retrieve it. level (str): Level name (``debug``, ``info``, etc..) to enable. Keyword Arguments: printout (bool): If False, logs will never be outputed. Returns: logging.Logger: Application logger. """root_logger=logging.getLogger(name)root_logger.setLevel(level)# Redirect outputs to the void space, mostly for usage within unittestsifnotprintout:fromioimportStringIOdummystream=StringIO()handler=logging.StreamHandler(dummystream)# Standard output with colored messageselse:handler=logging.StreamHandler()handler.setFormatter(colorlog.ColoredFormatter("%(asctime)s - %(log_color)s%(message)s",datefmt="%H:%M:%S"))root_logger.addHandler(handler)returnroot_logger
[docs]classNoOperationLogger:""" A fake logger which don't do anything, given messages to logging method just fall into void except for ``critical`` which raise the ``DependencyCombError`` exception. """def__init__(self,*args,**kwargs):passdefdebug(self,msg):passdefinfo(self,msg):passdefwarning(self,msg):passdeferror(self,msg):passdefcritical(self,msg):raiseDependencyCombError(msg)
[docs]classLoggerBase:""" A basic class just to ship the required logger object. This class should be at the last position in inheritance definition, since it must be called first because next classes may require its ``self.log`` attribute. """def__init__(self,*args,**kwargs):self.log=logging.getLogger(__pkgname__)