Explorar o código

修改日志目录,增加time日志记录推送开始请求和响应时间

locky hai 1 ano
pai
achega
06df6c2202
Modificáronse 2 ficheiros con 19 adicións e 5 borrados
  1. 15 3
      AnsjerPush/test_config/test_settings.py
  2. 4 2
      Controller/DetectControllerV2.py

+ 15 - 3
AnsjerPush/test_config/test_settings.py

@@ -170,7 +170,6 @@ LOGGING = {
     'disable_existing_loggers': True,
     'formatters': {
         'error_format': {
-            # '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': {
@@ -188,7 +187,7 @@ LOGGING = {
         'default': {
             'level': 'ERROR',
             'class': 'logging.handlers.RotatingFileHandler',
-            'filename': BASE_DIR + '/static/log/error.log',
+            'filename': BASE_DIR + '/static/log/error/error.log',
             'maxBytes': 1024 * 1024 * 5,  # 5 MB
             'backupCount': 5,
             'formatter': 'error_format',
@@ -207,11 +206,19 @@ LOGGING = {
             'formatter': 'standard',
             'encoding': 'utf-8',
         },
+        'time': {
+            'level': 'INFO',
+            'class': 'logging.handlers.TimedRotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/time/info.log',
+            'backupCount': 30,
+            'when': 'D',
+            'formatter': 'standard',
+            'encoding': 'utf-8',
+        },
     },
     'loggers': {
         'django': {
             'handlers': ['default', 'console'],
-            # 'handlers': ['mail_admins','default','console'],
             'level': 'ERROR',
             'propagate': True
         },
@@ -220,6 +227,11 @@ LOGGING = {
             'handlers': ['info'],
             'level': 'INFO',
             'propagate': False
+        },
+        'time': {
+            'handlers': ['info'],
+            'level': 'INFO',
+            'propagate': False
         }
     }
 }

+ 4 - 2
Controller/DetectControllerV2.py

@@ -6,6 +6,7 @@ from django.views.generic.base import View
 
 from Object.RedisObject import RedisObject
 from Service.DevicePushService import DevicePushService
+TIME_LOGGER = logging.getLogger('time')
 
 
 # 移动侦测V2接口
@@ -63,7 +64,7 @@ class NotificationV2View(View):
             uid = DevicePushService.decode_uid(etk, uidToken)
             if len(uid) != 20 and len(uid) != 14:
                 return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong uid'})
-            logger.info('消息推送V2****uid{}'.format(uid))
+            TIME_LOGGER.info('开始推送,uid:{},n_time:{},事件类型:{}'.format(uid, n_time, event_type))
             # 判断是否为系统消息
             is_sys_msg = DevicePushService.judge_sys_msg(int(event_type))
             if is_sys_msg:
@@ -133,7 +134,8 @@ class NotificationV2View(View):
             params['uid_set_push_list'] = uid_set_push_list
             params['code_dict'] = result
             result_dict = DevicePushService.get_push_url(**params)  # 获取S3对象上传链接
-            logger.info('{}触发时间{},推送URL{}'.format(uid, n_time, json.dumps(result_dict)))
+            TIME_LOGGER.info('推送响应,uid:{},n_time:{},事件类型:{},响应:{}'.format(
+                uid, n_time, event_type, json.dumps(result_dict)))
             return JsonResponse(status=200, data=result_dict)
         except Exception as e:
             logger.info('V2推送接口异常, errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))