瀏覽代碼

v1推送接口日志优化

peng 1 年之前
父節點
當前提交
8e04d41ace

+ 9 - 0
AnsjerPush/cn_config/cn_formal_settings.py

@@ -216,6 +216,15 @@ LOGGING = {
             'formatter': 'standard',
             'encoding': 'utf-8',
         },
+        'v1_push': {
+            'level': 'INFO',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/v1log/info.log',
+            'backupCount': 10,
+            'maxBytes': 1024 * 1024 * 2 * 1024,  # 2G
+            'formatter': 'standard',
+            'encoding': 'utf-8',
+        },
     },
     'loggers': {
         'django': {

+ 9 - 0
AnsjerPush/eur_config/eur_formal_settings.py

@@ -210,6 +210,15 @@ LOGGING = {
             'formatter': 'standard',
             'encoding': 'utf-8',
         },
+        'v1_push': {
+            'level': 'INFO',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/v1log/info.log',
+            'backupCount': 10,
+            'maxBytes': 1024 * 1024 * 2 * 1024,  # 2G
+            'formatter': 'standard',
+            'encoding': 'utf-8',
+        },
     },
     'loggers': {
         'django': {

+ 9 - 0
AnsjerPush/test_config/test_settings.py

@@ -215,6 +215,15 @@ LOGGING = {
             'formatter': 'standard',
             'encoding': 'utf-8',
         },
+        'v1_push': {
+            'level': 'INFO',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/v1log/info.log',
+            'backupCount': 10,
+            'maxBytes': 1024 * 1024 * 2 * 1024,  # 2G
+            'formatter': 'standard',
+            'encoding': 'utf-8',
+        },
     },
     'loggers': {
         'django': {

+ 9 - 0
AnsjerPush/us_config/formal_settings.py

@@ -217,6 +217,15 @@ LOGGING = {
             'formatter': 'standard',
             'encoding': 'utf-8',
         },
+        'v1_push': {
+            'level': 'INFO',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/v1log/info.log',
+            'backupCount': 10,
+            'maxBytes': 1024 * 1024 * 2 * 1024,  # 2G
+            'formatter': 'standard',
+            'encoding': 'utf-8',
+        },
     },
     'loggers': {
         'django': {

+ 5 - 2
Controller/DetectController.py

@@ -13,6 +13,8 @@ from Object.utils import LocalDateTimeUtil
 from Service.DevicePushService import DevicePushService
 from Service.EquipmentInfoService import EquipmentInfoService
 
+logger = logging.getLogger('v1_push')
+
 
 # 旧移动侦测接口
 class NotificationView(View):
@@ -35,7 +37,6 @@ class NotificationView(View):
         @param request_dict:event_type 设备事件类型
         @param request_dict:is_st 文件类型(0:无,1:图片,2:视频)
         """
-        logger = logging.getLogger('info')
         uidToken = request_dict.get('uidToken', None)
         etk = request_dict.get('etk', None)
         channel = request_dict.get('channel', '1')
@@ -49,7 +50,7 @@ class NotificationView(View):
             uid = DevicePushService.decode_uid(etk, uidToken)  # 解密uid
             if len(uid) != 20 and len(uid) != 14:
                 return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
-            logger.info("旧移动侦测接口的uid:{}".format(uid))
+            logger.info("旧移动侦测接口的uid:{},时间戳:{},事件类型:{}".format(uid, n_time, event_type))
             event_type = int(event_type)
             pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
             ykey = '{uid}_redis_qs'.format(uid=uid)
@@ -177,6 +178,7 @@ class NotificationView(View):
                     del up['uid_set__detect_interval']
                     del up['uid_set__detect_group']
                 res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
+                logger.info('推送响应,uid:{},n_time:{},事件类型:{},响应:{}'.format(uid, n_time, event_type, json.dumps(res_data)))
                 return JsonResponse(status=200, data=res_data)
 
             elif is_st == '3':
@@ -205,6 +207,7 @@ class NotificationView(View):
                     del up['uid_set__detect_group']
 
                 res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
+                logger.info('推送响应,uid:{},n_time:{},事件类型:{},响应:{}'.format(uid, n_time, event_type, json.dumps(res_data)))
                 return JsonResponse(status=200, data=res_data)
         except Exception as e:
             logger.info('旧推送接口异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))