我正在使用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
它没有打印调试信息,也没有按照我在控制台中指定的格式进行打印。
我错过了什么吗?
谢谢!