peng hace 2 años
padre
commit
ef403f1b73
Se han modificado 1 ficheros con 32 adiciones y 61 borrados
  1. 32 61
      VSeesResourceWeb/settings.py

+ 32 - 61
VSeesResourceWeb/settings.py

@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
 """
 
 from pathlib import Path
+import os
 
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
 BASE_DIR = Path(__file__).resolve().parent.parent
@@ -133,7 +134,7 @@ USE_TZ = True
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/3.2/howto/static-files/
 
-STATIC_URL = '/static/'
+STATIC_URL = '/logs/'
 
 # Default primary key field type
 # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
@@ -141,74 +142,44 @@ STATIC_URL = '/static/'
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 LOGGING = {
     'version': 1,
-    'disable_existing_loggers': True,
-    'formatters': {
-        'error_format': {
-            'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
+    'disable_existing_loggers': False if DEBUG else True,  # 是否禁用已经存在的日志器
+    'formatters': {  # 日志信息显示的格式
+        'verbose': {
+            'format': '%(levelname)s %(asctime)s %(module)s %(lineno)s %(message)s'
+            # "class": "pythonjsonlogger.jsonlogger.JsonFormatter"
         },
-        'standard': {
-            'format': '[%(asctime)s] [%(filename)s:%(lineno)d] [%(module)s:%(funcName)s] '
-                      '[%(levelname)s]- %(message)s'},
-
-    },
-    'filters': {
+        'simple': {
+            'format': '%(levelname)s %(asctime)s %(module)s %(funcName)s %(lineno)d %(message)s'
+            # "class": "pythonjsonlogger.jsonlogger.JsonFormatter"
+        },  # 日志记录级别+时间日期+模块名称+函数名称+行号+记录消息
     },
-    'handlers': {
-        'mail_admins': {
-            'level': 'ERROR',
-            'class': 'django.utils.log.AdminEmailHandler',
-            'include_html': True,
-        },
-        'default': {
-            'level': 'ERROR',
-            'class': 'logging.handlers.TimedRotatingFileHandler',
-            'filename': BASE_DIR / 'background/static/log/error/error.log',
-            'backupCount': 30,
-            'when': 'D',
-            'formatter': 'error_format',
+    'filters': {  # 对日志进行过滤
+        'require_debug_true': {  # django在debug模式下才输出日志
+            '()': 'django.utils.log.RequireDebugTrue',
         },
-        'console': {
-            'level': 'ERROR',
+    },
+    'handlers': {  # 日志处理方法
+        'console': {  # 向终端中输出日志
+            'level': 'DEBUG' if DEBUG else 'INFO',
+            'filters': ['require_debug_true'],  # debug为true才会输出
             'class': 'logging.StreamHandler',
-            'formatter': 'error_format'
-        },
-        'info': {
-            'level': 'INFO',
-            'class': 'logging.handlers.TimedRotatingFileHandler',
-            'filename': BASE_DIR / 'background/static/log/info/info.log',
-            'backupCount': 30,
-            'when': 'D',
-            'formatter': 'standard',
-            'encoding': 'utf-8',
+            'formatter': 'verbose'
         },
-        'pay': {
+        'info': {  # 向文件中输出日志
             'level': 'INFO',
-            'class': 'logging.handlers.TimedRotatingFileHandler',
-            'filename': BASE_DIR / 'background/static/log/pay/info.log',
-            'backupCount': 60,
-            'when': 'D',
-            'formatter': 'standard',
-            'encoding': 'utf-8',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': os.path.join(BASE_DIR / 'logs/', "info.log"),  # 日志文件的位置
+            'maxBytes': 300 * 1024 * 1024,  # 300M大小
+            'backupCount': 10,
+            'formatter': 'verbose',
+            'encoding': 'utf-8'
         },
     },
-    'loggers': {
-        'django': {
-            'handlers': ['default', 'console'],
-            # 'handlers': ['mail_admins','default','console'],
-            # 'level': 'ERROR',
-            'level': 'ERROR',
-            'propagate': False
-        },
-        # log 调用时需要当作参数传入
-        'info': {
-            'handlers': ['info'],
-            'level': 'INFO',
-            'propagate': False
-        },
-        'pay': {
-            'handlers': ['pay'],
-            'level': 'INFO',
-            'propagate': False
+    'loggers': {  # 日志器
+        "django": {        # 默认的logger应用如下配置
+            "handlers": ["info", "console"],
+            "propagate": True,
+            "level": "INFO"
         },
     }
 }