# django-redis 配置
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://192.168.3.109:6379/0",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
"session": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://192.168.3.109:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "session"
# 日志配置
LOG_DIR = os.path.join(BASE_DIR, "logs")
LOGGING = {
"version": 1,
"disable_existing_loggers": False, # 禁用已经存在的logger实例
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
"formatters": { # 定义了两种日志格式
"verbose": { # 详细
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
},
'simple': { # 简单
'format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
},
},
"handlers": { # 定义了三种日志处理方式
"mail_admins": { # 只有debug=False且Error级别以上发邮件给admin
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
},
'file': { # 对INFO级别以上信息以日志文件形式保存
'level': "INFO",
'class': 'logging.handlers.RotatingFileHandler', # 滚动生成日志,切割
'filename': os.path.join(LOG_DIR, 'django.log'), # 日志文件名
'maxBytes': 1024 * 1024 * 10, # 单个日志文件最大为10M
'backupCount': 5, # 日志备份文件最大数量
'formatter': 'simple', # 简单格式
'encoding': 'utf-8', # 放置中文乱码
},
"console": { # 打印到终端console
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
},
"root": {"level": "INFO", "handlers": ["console"]},
"loggers": {
"django.request": { # Django的request发生error会自动记录
"handlers": ["mail_admins"],
"level": "ERROR",
"propagate": True, # 向不向更高级别的logger传递
},
},
}