gpt4 book ai didi

python - Django - 记录不覆盖默认设置

转载 作者:行者123 更新时间:2023-11-28 19:22:16 51 4
gpt4 key购买 nike

我目前正在使用 Django 1.6.2 开发一个站点,但我无法正确进行日志记录配置。

我已经在设置文件中设置了“LOGGING”,但它似乎被忽略了。这是我的设置文件:

    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "duummy"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'channels'
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'my_app.urls'

WSGI_APPLICATION = 'my_app.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Brazil/East'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

# Logging
#

LOGGING_DIR = os.path.join(BASE_DIR, 'logs/')

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(asctime)s - %(module)s -> %(levelname)s - %(message)s'
}
},
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
}
},
'handlers': {
'console':{
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'debug_log_handler': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(LOGGING_DIR, 'debug_log'),
'formatter':'verbose'
},
'db_log_handler': {
'level': 'ERROR',
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(LOGGING_DIR, 'db_log'),
'when':'D',
'interval':1,
'formatter':'simple'
},
'request_log_handler': {
'level': 'ERROR',
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(LOGGING_DIR, 'request_log'),
'when':'D',
'interval':1,
'formatter':'simple'
},
'site_log_handler': {
'level': 'ERROR',
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(LOGGING_DIR, 'log'),
'when':'D',
'interval':1,
'formatter':'simple'
}
},
'loggers': {
'django': {
'handlers': ['console', 'debug_log_handler'],
'level': 'DEBUG',
'propagate': True,
'filters': ['require_debug_true']
},
'django.db.backends': {
'handlers': ['db_log_handler'],
'level': 'ERROR',
'propagate': True
},
'django.request': {
'handlers': ['request_log_handler'],
'level': 'ERROR',
'propagate': True
},
'test': {
'handlers': ['site_log_handler'],
'level': 'ERROR',
'propagate': True
},
}
}

当我运行服务器时,控制台输出如下信息:

[13/Mar/2014 01:25:12] "GET / HTTP/1.1" 404 2015

它没有打印调试信息,也没有以我为控制台指定的格式打印。

我错过了什么吗?

谢谢!

最佳答案

当您运行服务器时,似乎执行了“GET/”,Django 会将请求记录到“django.request”记录器。由于您将 LOGGING.disable_existing_loggers 设置为 True,它必须使用您配置的 django.request 设置。

在 LOGGING.loggers 中,您将 django.request 的级别设置为“错误”。但是,根据 the documentation,4XXs 仅记录为警告。 .只有 5XXs 被记录为错误。

关于python - Django - 记录不覆盖默认设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22369382/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com