diff options
| author | 陈冠林 <[email protected]> | 2019-01-25 16:07:48 +0800 |
|---|---|---|
| committer | 陈冠林 <[email protected]> | 2019-01-25 16:07:48 +0800 |
| commit | 3b263cf8079fb4fc718625a5a07aa61be4545531 (patch) | |
| tree | 2e007cd0a61047583d643b735f804459fdf34ff3 /VPN_CGI | |
| parent | 2d8d40209f769820e6544b46e3d9bc64350ea87e (diff) | |
增加日志和报错
Diffstat (limited to 'VPN_CGI')
| -rw-r--r-- | VPN_CGI/settings.py | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/VPN_CGI/settings.py b/VPN_CGI/settings.py index aa9575f..e016b08 100644 --- a/VPN_CGI/settings.py +++ b/VPN_CGI/settings.py @@ -14,7 +14,11 @@ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - +LOG_PATH = os.path.join(BASE_DIR, 'log') +# 如果地址不存在,则自动创建log文件夹 +# print(1) +# if os.path.exists(LOG_PATH): +# os.mkdir(LOG_PATH) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ @@ -114,7 +118,61 @@ USE_L10N = True USE_TZ = True -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/2.1/howto/static-files/ - STATIC_URL = '/static/' + +LOGGING = { + # version只能为1,定义了配置文件的版本,当前版本号为1.0 + "version": 1, + # True表示禁用logger + "disable_existing_loggers": False, + # 格式化 + 'formatters': { + 'default': { + 'format': '%(levelno)s %(funcName)s %(module)s %(asctime)s %(message)s' + }, + 'simple': { + 'format': '%(levelno)s %(module)s %(created)s %(message)s' + } + }, + + 'handlers': { + 'error_handlers': { + 'level': 'ERROR', + # 日志文件指定为5M, 超过5m重新命名,然后写入新的日志文件 + 'class': 'logging.handlers.RotatingFileHandler', + # 指定文件大小 + 'maxBytes': 5 * 1024, + # 指定文件地址 + 'filename': os.path.join(LOG_PATH, "error.log"), + 'formatter': 'default' + }, + 'debug_handlers': { + 'level': 'DEBUG', + # 日志文件指定为5M, 超过5m重新命名,然后写入新的日志文件 + 'class': 'logging.handlers.RotatingFileHandler', + # 指定文件大小 + 'maxBytes': 5 * 1024 * 1024, + # 指定文件地址 + 'filename': os.path.join(LOG_PATH, "debug.log"), + 'formatter': 'default' + } + }, + 'loggers': { + 'error': { + 'handlers': ['error_handlers'], + 'level': 'ERROR' + }, + 'debug': { + 'handlers': ['debug_handlers'], + 'level': 'DEBUG' + } + }, + + # 'filters': { + # 'require_debug_true': { + # '()': 'django.utils.log.RequireDebugTrue', + # }, + + # } +} + |
