Forráskód Böngészése

测试服,添加日志功能,给V2添加info日志

lhq 4 éve
szülő
commit
0059434fcd
2 módosított fájl, 33 hozzáadás és 3 törlés
  1. 18 0
      AnsjerPush/test_settings.py
  2. 15 3
      Controller/DetectControllerV2.py

+ 18 - 0
AnsjerPush/test_settings.py

@@ -164,6 +164,9 @@ LOGGING = {
             # 'format': '{"asctime":"%(asctime)s","thread":"%(threadName)s:%(thread)d","errorline":"%(lineno)d","errorlevel":"%(levelname)s","errorcontent":"%(message)s"}'
             'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
         },
+        'standard': {
+            'format': '[%(asctime)s] [%(filename)s:%(lineno)d] [%(module)s:%(funcName)s] '
+                      '[%(levelname)s]- %(message)s'},
     },
     'filters': {
     },
@@ -186,6 +189,15 @@ LOGGING = {
             'class': 'logging.StreamHandler',
             'formatter': 'error_format'
         },
+        'info': {
+            'level': 'INFO',
+            'class': 'logging.handlers.TimedRotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/info/info.log',
+            'backupCount': 30,
+            'when': 'D',
+            'formatter': 'standard',
+            'encoding': 'utf-8',
+        },
     },
     'loggers': {
         'django': {
@@ -194,5 +206,11 @@ LOGGING = {
             'level': 'ERROR',
             'propagate': True
         },
+        # log 调用时需要当作参数传入
+        'info': {
+            'handlers': ['info'],
+            'level': 'INFO',
+            'propagate': False
+        }
     }
 }

+ 15 - 3
Controller/DetectControllerV2.py

@@ -54,7 +54,7 @@ class NotificationView(View):
 
     def validation(self, request_dict):
         logger = logging.getLogger('info')
-        logger.info("进来了")
+        logger.info("进来推送接口了")
         logger.info(request_dict)
         uidToken = request_dict.get('uidToken', None)
         etk = request_dict.get('etk', None)
@@ -81,7 +81,8 @@ class NotificationView(View):
         else:
             utko = UidTokenObject(uidToken)
             uid = utko.UID
-
+        logger.info("当前调用推送接口的uid:")
+        logger.info(uid)
         pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
         # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
         ykey = '{uid}_redis_qs'.format(uid=uid)
@@ -159,7 +160,8 @@ class NotificationView(View):
             print("没有redi_list")
             res_data = {'code': 0, 'msg': 'no redi_list success!'}
             return JsonResponse(status=200, data=res_data)
-
+        logger.info("(从数据库中获取的所有信息)redis_list:")
+        logger.info(redis_list)
         # is_sys_msg = self.is_sys_msg(int(event_type))
         nickname = redis_list[0]['uid_set__nickname']
         detect_interval = redis_list[0]['uid_set__detect_interval']
@@ -249,13 +251,17 @@ class NotificationView(View):
             kwag_args['token_val'] = token_val
             kwag_args['msg_title'] = msg_title
             kwag_args['msg_text'] = msg_text
+            logger.info('推送要的数据:')
+            logger.info(kwag_args)
             push_server_status = 0
             #推送
             if detect_med_type == 2 or detect_med_type == 0:
                 if push_type == 0:  # ios apns
                     print('do_apns')
+                    logger.info('dp_apns')
                     # self.do_apns(**kwag_args)
                     do_apns_code = self.do_apns(**kwag_args)
+                    logger.info("出来do_apns了")
                     if isinstance(do_apns_code, int):
                         push_server_status = do_apns_code
                     else:
@@ -556,6 +562,8 @@ class NotificationView(View):
 
     def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
                 msg_text):
+        logger = logging.getLogger('info')
+        logger.info("进来do_apns函数了")
         try:
             cli = apns2.APNSClient(mode=APNS_MODE,
                                    client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
@@ -569,6 +577,8 @@ class NotificationView(View):
             n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
             res = cli.push(n=n, device_token=token_val, topic=appBundleId)
             print(res.status_code)
+            logger.info("推送状态:")
+            logger.info(res.status_code)
 
             #     200, 推送成功。
             #   400, 请求有问题。
@@ -580,11 +590,13 @@ class NotificationView(View):
             else:
                 print('apns push fail')
                 print(res.reason)
+                logger.info(res.reason)
                 return res.status_code
         except (ValueError, ArithmeticError):
             return 'The program has a numeric format exception, one of the arithmetic exceptions'
         except Exception as e:
             print(repr(e))
+            logger.info(repr(e))
             return repr(e)
 
     def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):