django日志配置

2/10/2017来源:ASP.NET技巧人气:1497

LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'main_format':{ 'format': '[%(levelname)s] [%(asctime)s] [%(pathname)s] [%(module)s] [%(lineno)d] [%(message)s] ', 'datefmt': '%Y-%m-%d %H:%M:%S' }, }, 'handlers': { 'main':{ 'level': 'INFO', 'class': 'logging.handlers.RotatingFileHandler', 'filename': os.path.join(PROJECT_DIR, '../log/Main.log'),#you need define your VAR_ROOT variable that points to your project path,and mkdir a logs directory in your project root path. 'backupCount': 5, 'maxBytes': 16777216, # 16megabytes(16M) 'formatter': 'main_format' }, 'django_request_logfile':{ 'level': 'INFO', 'class': 'logging.handlers.RotatingFileHandler', 'filename': os.path.join(PROJECT_DIR, '../log/request.log'),#you need define your VAR_ROOT variable that points to your project path,and mkdir a logs directory in your project root path. 'backupCount': 5, 'maxBytes': 16777216, # 16megabytes(16M) 'formatter': 'main_format' } }, 'loggers': { 'Main': { 'handlers': ['main'], 'level': 'INFO', } , 'django.request':{ 'handlers': ['django_request_logfile'], 'level': 'ERROR', 'propagate': False } } }