日志跟踪

日志功能添加

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)))

你可能感兴趣的:(日志跟踪)