[docs]defget_logger(name):"""Get the logger with the associated name. Args: name (str): Name of the logger to get. Returns: The logger object with the associated name. """logger=logging.getLogger(name)ifnotlen(logger.handlers):logger.setLevel(logging.DEBUG)stdout_handler=logging.StreamHandler(sys.stdout)stdout_handler.setLevel(logging.INFO)stdout_handler.setFormatter(logging.Formatter("%(message)s"))logger.addHandler(stdout_handler)returnlogger
[docs]deflog_title(logger,title):"""Log with a title."""logger.info("\n"+"*"*(len(title)+4))logger.info("* %s *"%title)logger.info("*"*(len(title)+4))logger.info("")
[docs]deflog_subtitle(logger,title,underline="="):"""Log with a subtitle."""logger.info("")logger.info("%s"%title)logger.info(underline*len(title))
[docs]deftime_elapsed(start_time):"""How much time has elapsed since the search started. Args: start_time (int): Time when search started. Returns: str: elapsed time formatted as a string [H:]MM:SS """time_diff=time.time()-start_time# Source: tqdm.std.tqdm.format_intervalmins,s=divmod(int(time_diff),60)h,m=divmod(mins,60)ifh:return"{0:d}:{1:02d}:{2:02d}".format(h,m,s)else:return"{0:02d}:{1:02d}".format(m,s)
[docs]deflog_batch_times(logger,batch_times):"""Used to print out the batch times. Args: logger: the logger. batch_times: dict with (batch number, {pipeline name, pipeline time}). """log_title(logger,"Batch Time Stats")forbatch_numberinbatch_times:subtitle="Batch "+str(batch_number)+" time stats:"log_subtitle(logger,subtitle)forpipeline_nameinbatch_times[batch_number]:logger.info("\n"+pipeline_name+": "+f"{batch_times[batch_number][pipeline_name]:.2f} seconds",)logger.info("")