[docs]deflog_once(message:str,level:Union[str,int]=logging.INFO,logger:Optional[logging.Logger]=None,):""" Log a message only once (based on the message content and the source code location). Args: message (str): message to log level (str or int): log level, could be "critical", "error", "warning", "info", "debug" or corresponding int value (default: "info") """call_stack=stack()actual_frame=call_stack[1]forframe_infoincall_stack[1:]:ifnotframe_info.filename.startswith("<"):# found a valid caller frame instead of <@beartype(...)>actual_frame=frame_infobreakframe_info=getframeinfo(actual_frame.frame)key=(frame_info.filename,frame_info.lineno,message)ifkeynotin_has_logged:ifisinstance(level,str):level=_name_to_level[level.lower()]ifloggerisNone:logger=_default_loggerlogger.log(level,message)_has_logged.add(key)