Pārlūkot izejas kodu

error_info日志文件记录推送异常

locky 1 gadu atpakaļ
vecāks
revīzija
1ca4cd9925

+ 15 - 1
AnsjerPush/cn_config/cn_formal_settings.py

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

+ 15 - 1
AnsjerPush/dev_config/local_settings.py

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

+ 15 - 1
AnsjerPush/eur_config/eur_formal_settings.py

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

+ 15 - 1
AnsjerPush/test_config/test_settings.py

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

+ 15 - 1
AnsjerPush/us_config/formal_settings.py

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

+ 5 - 2
Controller/DetectControllerV2.py

@@ -11,6 +11,8 @@ from Service.DevicePushService import DevicePushService
 from concurrent.futures import ThreadPoolExecutor
 
 TIME_LOGGER = logging.getLogger('time')
+ERROR_INFO_LOGGER = logging.getLogger('error_info')
+
 # 创建一个全局的线程池实例
 # 线程池最大数量
 # 1、CPU密集型:操作内存处理的业务,一般线程数设置为:CPU核数 + 1 或者 CPU核数*2。核数为4的话一般设置5或8
@@ -180,8 +182,9 @@ class NotificationV2View(View):
                 uid, n_time, event_type, json.dumps(res_data)))
             return JsonResponse(status=200, data=res_data)
         except Exception as e:
-            TIME_LOGGER.info('V2推送接口异常uid:{},etk:{},error_line:{},error_msg:{}'.
-                             format(uid, etk, e.__traceback__.tb_lineno, repr(e)))
+            ERROR_INFO_LOGGER.info(
+                'V2推送接口异常,uid:{},etk:{},error_line:{},error_msg:{}'.
+                format(uid, etk, e.__traceback__.tb_lineno, repr(e)))
             data = {
                 'error_line': e.__traceback__.tb_lineno,
                 'error_msg': repr(e)

+ 9 - 4
Service/DevicePushService.py

@@ -39,6 +39,7 @@ from django.db import close_old_connections
 
 LOGGING = logging.getLogger('info')
 TIME_LOGGER = logging.getLogger('time')
+ERROR_INFO_LOGGER = logging.getLogger('error_info')
 
 
 class DevicePushService:
@@ -218,8 +219,9 @@ class DevicePushService:
                     )
                     push_thread.start()
         except Exception as e:
-            TIME_LOGGER.info('APP通知V2推送接口异常uid:{},error_line:{},error_msg:{}'
-                             .format(params['uid'], e.__traceback__.tb_lineno, repr(e)))
+            ERROR_INFO_LOGGER.info(
+                '推送消息线程异常,uid:{},error_line:{},error_msg:{}'
+                .format(params['uid'], e.__traceback__.tb_lineno, repr(e)))
 
     @classmethod
     def save_msg_push(cls, **params):
@@ -316,7 +318,9 @@ class DevicePushService:
                         equipment_info_model.objects.bulk_create(equipment_info_list)
             return True
         except Exception as e:
-            LOGGING.info('推送消息或存表异常uid:{}, error_line:{}, error_msg:{}'.format(uid, e.__traceback__.tb_lineno, repr(e)))
+            ERROR_INFO_LOGGER.info(
+                '保存推送数据和推送消息线程异常,uid:{}, error_line:{}, error_msg:{}'.
+                format(uid, e.__traceback__.tb_lineno, repr(e)))
             return False
 
     @classmethod
@@ -452,7 +456,8 @@ class DevicePushService:
                                        content=push_kwargs, push_result=push_result, push_type=push_type)
             return push_result
         except Exception as e:
-            LOGGING.error('发送推送异常,error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            ERROR_INFO_LOGGER.info(
+                '发送推送线程异常,error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             return False
 
     @staticmethod