您的位置:首页 > 编程语言 > Go语言

django日志配置

2016-01-06 14:26 537 查看
#配置应用的日志handlers
APP_LOG_HANDLERS = ['default', 'console', 'default_debug']
# settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s FuncName:%(funcName)s LINE:%(lineno)d [%(levelname)s]- %(message)s',
'datefmt' : "%Y-%m-%d %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s',
'datefmt' : "%Y-%m-%d %H:%M:%S"
},
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s',
'datefmt' : "%Y-%m-%d %H:%M:%S"
},
'verbose1': {
'format' : "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s:%(lineno)s] %(message)s",
'datefmt' : "%Y-%m-%d %H:%M:%S"
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'DEBUG',
#             'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
'include_html': False,
#             'email_backend': 'django.core.mail.backends.filebased.EmailBackend',
},
'default': {
'level':'INFO',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(LOG_DIR, 'autoop_info.log'),
'maxBytes': 1024 * 1024 * 500,  # 5 MB
'backupCount': 5,
'formatter':'verbose1',
},
'default_debug': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(LOG_DIR, 'autoop_debug.log'),
'maxBytes': 1024 * 1024 * 500,  # 5 MB
'backupCount': 5,
'formatter':'verbose1',
},
'console':{
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose1'
},
'request_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(LOG_DIR, 'autoop_script.log'),
'maxBytes': 1024 * 1024 * 500,  # 5 MB
'backupCount': 5,
'formatter':'verbose1',
},
'scprits_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(LOG_DIR, 'autoop_script.log'),
'maxBytes': 1024 * 1024 * 500,  # 5 MB
'backupCount': 5,
'formatter':'verbose1',
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'DEBUG',
'propagate': True,
},
'django': {
'handlers': ['default', 'console'],
'level': 'DEBUG',
'propagate': False
},
'django.request': {
'handlers': ['request_handler', 'console'],
'level': 'DEBUG',
'propagate': False
},
'scripts': {
'handlers': ['scprits_handler', 'console'],
'level': 'ERROR',
'propagate': False
},
'app1':{
'handlers': APP_LOG_HANDLERS,
'level': 'DEBUG',
'propagate': True
},
'app2':{
'handlers': APP_LOG_HANDLERS,
'level': 'DEBUG',
'propagate': True
},
'utils':{
'handlers': APP_LOG_HANDLERS,
'level': 'DEBUG',
'propagate': True
},
'app.custom':{
'handlers': APP_LOG_HANDLERS,
'level': 'DEBUG',
'propagate': True
},
}
}

import logging
logger = logging.getLogger(__name__)
or
logger = logging.getLogger("app.custom")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django log 日志