Procházet zdrojové kódy

V2添加info日志

lhq před 4 roky
rodič
revize
2eb334e31d
2 změnil soubory, kde provedl 21 přidání a 1 odebrání
  1. 18 0
      AnsjerPush/formal_settings.py
  2. 3 1
      Controller/DetectControllerV2.py

+ 18 - 0
AnsjerPush/formal_settings.py

@@ -167,6 +167,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': {
     },
@@ -189,6 +192,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': {
@@ -197,5 +209,11 @@ LOGGING = {
             'level': 'ERROR',
             'propagate': False
         },
+        # log 调用时需要当作参数传入
+        'info': {
+            'handlers': ['info'],
+            'level': 'INFO',
+            'propagate': False
+        }
     }
 }

+ 3 - 1
Controller/DetectControllerV2.py

@@ -11,6 +11,7 @@
 @file: DetectController.py
 @Contact: chanjunkai@163.com
 """
+import logging
 import os
 import time
 
@@ -52,7 +53,8 @@ class NotificationView(View):
         return self.validation(request.POST)
 
     def validation(self, request_dict):
-
+        logger = logging.getLogger('info')
+        logger.info(request_dict)
         uidToken = request_dict.get('uidToken', None)
         etk = request_dict.get('etk', None)
         channel = request_dict.get('channel', '1')