什么是创建这些Django数据库日志条目?

时间:2017-09-11 16:29:50

标签: django

我的开发服务器的Django数据库日志文件非常大,因为每分钟都会记录一次特定事件:

[10/Sep/2017 21:02:02] DEBUG [django.db.backends:89] (0.001) DELETE FROM "django_session" WHERE "django_session"."expire_date" < '2017-09-10T21:02:02.514421+00:00'::timestamptz; args=(datetime.datetime(2017, 9, 10, 21, 2, 2, 514421, tzinfo=<UTC>),)
[10/Sep/2017 21:03:02] DEBUG [django.db.backends:89] (0.002) DELETE FROM "django_session" WHERE "django_session"."expire_date" < '2017-09-10T21:03:02.265801+00:00'::timestamptz; args=(datetime.datetime(2017, 9, 10, 21, 3, 2, 265801, tzinfo=<UTC>),)
[10/Sep/2017 21:04:02] DEBUG [django.db.backends:89] (0.002) DELETE FROM "django_session" WHERE "django_session"."expire_date" < '2017-09-10T21:04:02.033147+00:00'::timestamptz; args=(datetime.datetime(2017, 9, 10, 21, 4, 2, 33147, tzinfo=<UTC>),)

我的设置文件包含这些与会话相关的指令:

DEBUG = True
SESSION_COOKIE_SECURE = True
MIDDLEWARE_CLASSES = (
    # ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    # ...
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    # ...
)

SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
SESSION_COOKIE_AGE = 60 * 60
# Refresh session state with every request.  This effectively creates
# a "sliding" session expiration.  A user will remain signed in so
# long as they send at least one request every SESSION_COOKIE_AGE minutes.
SESSION_SAVE_EVERY_REQUEST = True

INSTALLED_APPS = [
    # ...
    'django.contrib.sessions',
    # ...
]

我的LOG设置中没有与会话相关的内容。导致这些DEBUG条目的原因是什么方法可以禁用它们或者至少降低它们的频率?

1 个答案:

答案 0 :(得分:0)

黄金答案在这里添加 settings.py 文件。你需要删除或注释掉这些行,这些生成数据库日志委托

 DEBUG = True
 '''
 LOGGING = {
 'version': 1,
 'filters': {
     'require_debug_true': {
         '()': 'django.utils.log.RequireDebugTrue',
     }
 },
 'handlers': {
     'console': {
         'level': 'DEBUG',
         'filters': ['require_debug_true'],
         'class': 'logging.StreamHandler',
     }
 },
 'loggers': {
     'django.db.backends': {
         'level': 'DEBUG',
         'handlers': ['console'],
     }
 }
}
'''