django日志配置

来源:互联网 发布:数据库分区表 编辑:程序博客网 时间:2024/05/01 21:22
#配置应用的日志handlersAPP_LOG_HANDLERS = ['default', 'console', 'default_debug']# settings.pyLOGGING = {    '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 logginglogger = logging.getLogger(__name__)orlogger = logging.getLogger("app.custom")
0 0
原创粉丝点击