日志跟踪

日志功能添加

if not os.path.exists('../log'):
os.makedirs('../log')

以时间戳为log文件名

fileName = str(datetime.datetime.now())
fileName = fileName.replace(" ", "-")
fileName = fileName.replace(".", "")
fileName = fileName.replace(":", "-")
generate_file = "../log/"+fileName+".log"

for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
file = open(generate_file,encoding="utf-8",mode="a")
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
stream= file)

代码应用:

      if pos_y >= self.map_info.near_storage_y and svr_sim_agv.id not in self.lock_storage:
            self.lock_storage.append(svr_sim_agv.id)
            logging.info(f'{svr_sim_agv.id} is at posId:{svr_sim_agv.pos} and is locked in storage_domain')

        if svr_sim_agv.pos in self.charge_domain and svr_sim_agv.id not in self.lock_charge:
            self.lock_charge.append(svr_sim_agv.id)
            logging.info(f'{svr_sim_agv.id} is at  posId:{svr_sim_agv.pos} and is locked in charge_domain')
            print("----------------0003")
        if svr_sim_agv.pos in self.cam_domain and svr_sim_agv.id not in self.lock_cam:
            self.lock_cam.append(svr_sim_agv.id)
            logging.info(f'{svr_sim_agv.id} is at  posId:{svr_sim_agv.pos} and is locked in cam_domain')
            print("----------------0004")

        if svr_sim_agv.id in self.lock_storage and svr_sim_agv.pos in self.storage_exit_pos:
            logging.info('Bself.lock_storage = %s' % (str(self.lock_storage)))
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容