From f8e781a472502ff7f6ef1b2b279d752f4fa8620f Mon Sep 17 00:00:00 2001 From: Attila-Mihaly Balazs Date: Thu, 9 Jan 2014 13:25:09 +0200 Subject: [PATCH] Configure logging "the Django way" and ensure that all messages are written to the logfile --- settings_local.py.dist | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/settings_local.py.dist b/settings_local.py.dist index 31ad226..f48a8e1 100644 --- a/settings_local.py.dist +++ b/settings_local.py.dist @@ -3,14 +3,33 @@ import os.path SITE_SRC_ROOT = os.path.dirname(__file__) LOG_FILENAME = 'django.osqa.log' - -#for logging -import logging -logging.basicConfig( - filename=os.path.join(SITE_SRC_ROOT, 'log', LOG_FILENAME), - level=logging.ERROR, - format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s', -) +LOGGING = { + 'version': 1, + 'formatters': { + 'default': { + 'format': '%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s', + } + }, + 'handlers': { + 'file': { + 'level': 'DEBUG', + 'class': 'logging.FileHandler', + 'formatter': 'default', + 'filename': os.path.join(SITE_SRC_ROOT, 'log', LOG_FILENAME), + }, + }, + 'loggers' : { + # ensure that all log entries are propagated to root + 'django': { 'propagate': True }, + 'django.request': { 'propagate': True }, + 'django.security': { 'propagate': True }, + 'py.warnings': { 'propagate': True }, + }, + 'root': { + 'handlers': ['file'], + 'level': 'DEBUG', + }, +} #ADMINS and MANAGERS ADMINS = () -- 2.39.5