Pārlūkot izejas kodu

修改定制推送日志配置,更新设备影子打印

locky 1 gadu atpakaļ
vecāks
revīzija
069ef80f22

+ 14 - 0
AnsjerPush/test_config/test_settings.py

@@ -224,6 +224,15 @@ LOGGING = {
             'formatter': 'standard',
             'encoding': 'utf-8',
         },
+        'customized_push': {
+            'level': 'INFO',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/customized_push/info.log',
+            'backupCount': 10,
+            'maxBytes': 1024 * 1024 * 2 * 100,  # 100M
+            'formatter': 'standard',
+            'encoding': 'utf-8',
+        },
     },
     'loggers': {
         'django': {
@@ -246,6 +255,11 @@ LOGGING = {
             'handlers': ['v1_push'],
             'level': 'INFO',
             'propagate': False
+        },
+        'customized_push': {
+            'handlers': ['customized_push'],
+            'level': 'INFO',
+            'propagate': False
         }
     }
 }

+ 5 - 5
AnsjerPush/us_config/formal_settings.py

@@ -259,9 +259,9 @@ LOGGING = {
             'propagate': False
         }
     },
-        'customized_push': {
-            'handlers': ['customized_push'],
-            'level': 'INFO',
-            'propagate': False
-        }
+    'customized_push': {
+        'handlers': ['customized_push'],
+        'level': 'INFO',
+        'propagate': False
+    }
 }

+ 6 - 10
Controller/ShadowController.py

@@ -85,14 +85,12 @@ def update_device_shadow(request):
     else:
         return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
 
-    logger = logging.getLogger('info')
-    logger.info('---更新设备影子---, 服务器地区:{}, 参数:{}'.format(CONFIG_INFO, request_dict.dict()))
     # 如果为美洲服,异步请求更新国内和欧洲数据
     if CONFIG_INFO == CONFIG_US:
         domain_name_list = ['push.zositechc.cn', 'push.zositeche.com']
         request_thread = threading.Thread(target=do_request_thread, args=(domain_name_list, request_dict.dict()))
         request_thread.start()
-
+    logger = logging.getLogger('info')
     try:
         etk = request_dict.get('etk', None)
         eto = ETkObject(etk)
@@ -100,14 +98,14 @@ def update_device_shadow(request):
         if not uid:
             return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
 
+        logger.info('{} 更新设备影子参数: {}'.format(uid, request_dict.dict()))
+
         nowTime = int(time.time())
 
         # 重置按钮
         is_reset = request_dict.get('is_reset', None)
         # 传1则重置设备信息
         if is_reset == '1':
-            logger.info('设备重置: {}'.format(uid))
-
             # 重置语音提示
             uid_channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid)
             if uid_channel_qs.exists():
@@ -132,7 +130,6 @@ def update_device_shadow(request):
 
             # 关闭AI
             AiService.objects.filter(uid=uid, use_status=1).update(detect_status=0, detect_group='')
-            logger.info('{}重置成功'.format(uid))
 
         ucode = request_dict.get('ucode', None)
         version = request_dict.get('version', None)
@@ -199,7 +196,6 @@ def update_device_shadow(request):
         if country_qs.exists():
             country = country_qs[0]['id']
             qs_dict['tb_country'] = country
-        logger.info('{} qs_dict: {}'.format(uid, qs_dict))
 
         us_qs = UidSetModel.objects.filter(uid=uid)
         if us_qs.exists():
@@ -213,11 +209,11 @@ def update_device_shadow(request):
             qs_dict['uid'] = uid
             qs_dict['addTime'] = nowTime
             UidSetModel.objects.create(**qs_dict)
-        logger.info('***设备影子保存成功{}'.format(uid))
         return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
     except Exception as e:
-        logger.info('更新设备影子异常: {}'.format(repr(e)))
-        return JsonResponse(status=200, data={'code': 0, 'update_shadow_error': repr(e)})
+        error_info = 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e))
+        logger.info('更新设备影子异常: {}'.format(error_info))
+        return JsonResponse(status=200, data={'code': 0, 'error': error_info})
 
 
 def do_request_thread(domain_name_list, data):