[docs]classSetupLog(object):default_level=logging.INFOdefault_logs={"RF2depthlog":("RF2depth",default_level,"stream_handler"),"RFlog":("RF",default_level,"stream_handler"),"Batlog":("Bat",default_level,"stream_handler","file_handler"),"CCPlog":("CCP",default_level,"stream_handler"),"ModCreatorlog":("ModCreator",default_level,"stream_handler"),"PickDepthlog":("PickDepth",default_level,"stream_handler")}def__init__(self,filename=join(expanduser('~'),'.RF.log')):""" use default_logs to gen loggers change default_logs for future changes if needed, check logger level with logger.getEffectiveLevel """self.filename=filenamefh=logging.FileHandler(filename,mode='w')ch=logging.StreamHandler()formatter=logging.Formatter('%(asctime)s [%(name)s] %(levelname)s: %(message)s')fh.setFormatter(formatter)ch.setFormatter(formatter)forloger_branch,configinself.default_logs.items():# init, setlevellog=logging.getLogger(config[0])log.setLevel(config[1])# add handlerifnotlog.hasHandlers():if"file_handler"inconfig:log.addHandler(fh)if"stream_handler"inconfig:log.addHandler(ch)# attach to classsetattr(self,loger_branch,log)