Browse Source

修改AI推送日志文件写入到time文件夹下

zhangdongming 1 năm trước cách đây
mục cha
commit
9f00de392d
2 tập tin đã thay đổi với 17 bổ sung15 xóa
  1. 16 14
      Controller/AiController.py
  2. 1 1
      Object/SageMakerAiObject.py

+ 16 - 14
Controller/AiController.py

@@ -35,6 +35,8 @@ from Object.enums.MessageTypeEnum import MessageTypeEnum
 from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService
 
+TIME_LOGGER = logging.getLogger('time')
+
 
 # AI服务
 class AiView(View):
@@ -72,8 +74,7 @@ class AiView(View):
         n_time = request_dict.get('n_time', None)
         channel = request_dict.get('channel', '1')
         receiveTime = int(time.time())
-        logger = logging.getLogger('info')
-        logger.info('*****进入into----ai--api,etk={etk}'.format(etk=etk))
+        TIME_LOGGER.info('*****进入into----ai--api,etk={etk}'.format(etk=etk))
         if not etk:
             return response.json(444)
         dir_path = ''
@@ -82,7 +83,7 @@ class AiView(View):
             # 解密uid及判断长度
             eto = ETkObject(etk)
             uid = eto.uid
-            logger.info(f'etk解析uid={uid},n_time={n_time}')
+            TIME_LOGGER.info(f'etk解析uid={uid},n_time={n_time},etk:{etk}')
             if len(uid) != 20 and len(uid) != 14:
                 return response.json(444)
 
@@ -90,13 +91,14 @@ class AiView(View):
             AiServiceQuery = AiService.objects.filter(uid=uid, detect_status=1, use_status=1, endTime__gt=receiveTime) \
                 .values('detect_group', 'orders__payType', 'addTime')
             if not AiServiceQuery.exists():
-                logger.info(f'uid={uid}AI服务未开通或已到期')
+                TIME_LOGGER.info(f'uid={uid}AI服务未开通或已到期')
                 return response.json(173)
             detect_group = AiServiceQuery[0]['detect_group']
 
             file_post_one = request_dict.get('fileOne', None)
             file_post_two = request_dict.get('fileTwo', None)
             file_post_three = request_dict.get('fileThree', None)
+            TIME_LOGGER.info(f'图1:{file_post_one[:30]},图2:{file_post_two[:30]},图3:{file_post_three[:30]}')
 
             file_list = [file_post_one, file_post_two, file_post_three]
             del file_post_one, file_post_two, file_post_three
@@ -113,7 +115,7 @@ class AiView(View):
                        'uid_set__detect_group',
                        'uid_set__channel')
             if not uid_push_qs.exists():
-                logger.info(f'uid={uid},用户没有开启AI推送')
+                TIME_LOGGER.info(f'uid={uid},用户没有开启AI推送')
                 return response.json(173)
 
             ai_server = 'sageMaker'
@@ -133,7 +135,7 @@ class AiView(View):
                     sage_maker.save_push_message(uid, n_time, uid_push_qs, channel, res, file_list)
                     return response.json(0)
 
-            logger.info(f'*****执行Reko,uid={uid} run {ai_server}')
+            TIME_LOGGER.info(f'*****执行Reko,uid={uid} run {ai_server}')
             dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(n_time))
             if not os.path.exists(dir_path):
                 os.makedirs(dir_path)
@@ -170,7 +172,7 @@ class AiView(View):
                 return response.json(173)
 
             labels = self.labelsCoords(detect_group, rekognition_res, image_size)  # 检查标签是否符合用户选择的识别类型
-            logger.info('*****执行完Rekognition得到labels')
+            TIME_LOGGER.info('*****执行完Rekognition得到labels')
 
             # 将识别结果存到S3以及DynamoDB
             AiView.store_image_results_to_dynamo_and_s3(file_path_list, uid, channel, n_time, labels, rekognition_res)
@@ -178,13 +180,13 @@ class AiView(View):
                 # 需要删除图片
                 self.del_path(dir_path)
                 self.del_path(dir_path + '.jpg')
-                logger.info('*****uid={},删除图片成功,路径为:{}'.format(uid, dir_path))
+                TIME_LOGGER.info('*****uid={},删除图片成功,路径为:{}'.format(uid, dir_path))
                 return response.json(10055)
             eventType = labels['eventType']
             label_str = ','.join(labels['label_list'])
             new_bounding_box_dict = labels['new_bounding_box_dict']
-            logger.info(eventType)
-            logger.info(label_str)
+            TIME_LOGGER.info(eventType)
+            TIME_LOGGER.info(label_str)
 
             # 上传缩略图到s3
             file_dict = {}
@@ -212,7 +214,7 @@ class AiView(View):
                 if tz is None or tz == '':
                     tz = 0
                 local_date_time = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang='cn')
-                logger.info('*****AI消息存库{},{},{}'.format(uid, local_date_time, tz))
+                TIME_LOGGER.info('*****AI消息存库{},{},{}'.format(uid, local_date_time, tz))
                 # 以下是存库
                 userID_id = up["userID_id"]
                 if userID_id not in userID_ids:
@@ -255,7 +257,7 @@ class AiView(View):
                     elif push_type == 2:  # android jpush
                         self.do_jpush(**kwargs)
                 except Exception as e:
-                    logger.info(
+                    TIME_LOGGER.info(
                         '*****error,uid={uid},errLine={errLine}, errMsg={errMsg}'
                             .format(uid=uid, errLine=e.__traceback__.tb_lineno, errMsg=repr(e)))
                     continue
@@ -271,7 +273,7 @@ class AiView(View):
                 'errLine': e.__traceback__.tb_lineno,
                 'errMsg': repr(e)
             }
-            logger.info(f'rekognition识别异常删除图片 uid:{uid},errMsg={data}')
+            TIME_LOGGER.info(f'rekognition识别异常删除图片 uid:{uid},errMsg={data}')
             return response.json(48, data)
         except Exception as e:
             print(e)
@@ -279,7 +281,7 @@ class AiView(View):
                 'errLine': e.__traceback__.tb_lineno,
                 'errMsg': repr(e)
             }
-            logger.info(f'rekognition识别errMsg={data}')
+            TIME_LOGGER.info(f'rekognition识别errMsg={data}')
             return response.json(48, data)
 
     def del_path(self, path):

+ 1 - 1
Object/SageMakerAiObject.py

@@ -27,7 +27,7 @@ from Service.EquipmentInfoService import EquipmentInfoService
 from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
 from Service.PushService import PushObject
 
-LOGGER = logging.getLogger('info')
+LOGGER = logging.getLogger('time')
 
 
 class SageMakerAiObject: