Add support for logging errors during in production mode.

Add COMMON_PRODUCTION_ERROR_LOG_PATH to control path of log file.
Defaults to mayan/error.log.
Add support logging request exceptions.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2017-07-13 03:30:51 -04:00
parent 8c4db068af
commit 2817ec17be
7 changed files with 39 additions and 3 deletions

1
.gitignore vendored
View File

@@ -18,6 +18,7 @@ htmlcov/
mayan/media/
mayan/media/document_cache/
mayan/settings/local.py
mayan/error.log
settings_local.py
static_collected/
/celerybeat-schedule

View File

@@ -4,6 +4,10 @@
- Add support for emailing documents to a recipient list. GitLab #396.
- Backport metadata widget changes from @Macrobb. GitLab #377.
- Make users and group searchable.
- Add support for logging errors during in production mode.
Add COMMON_PRODUCTION_ERROR_LOG_PATH to control path of log file.
Defaults to mayan/error.log.
- Add support logging request exceptions.
2.5.2 (2017-07-08)
==================

View File

@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
from datetime import timedelta
import logging
import os
from kombu import Exchange, Queue
@@ -30,7 +31,7 @@ from .literals import DELETE_STALE_UPLOADS_INTERVAL
from .menus import menu_about, menu_main, menu_tools, menu_user
from .licenses import * # NOQA
from .queues import * # NOQA - Force queues registration
from .settings import setting_auto_logging
from .settings import setting_auto_logging, setting_production_error_log_path
from .tasks import task_delete_stale_uploads # NOQA - Force task registration
logger = logging.getLogger(__name__)
@@ -154,13 +155,15 @@ class CommonApp(MayanAppConfig):
if setting_auto_logging.value:
if settings.DEBUG:
level = 'DEBUG'
handlers = ['console']
else:
level = 'ERROR'
handlers = ['console', 'logfile']
loggers = {}
for project_app in apps.apps.get_app_configs():
loggers[project_app.name] = {
'handlers': ['console'],
'handlers': handlers,
'propagate': True,
'level': level,
}
@@ -179,7 +182,11 @@ class CommonApp(MayanAppConfig):
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'intermediate'
}
},
'logfile': {
'class': 'logging.handlers.WatchedFileHandler',
'filename': setting_production_error_log_path.value,
},
},
'loggers': loggers
}

View File

@@ -0,0 +1,13 @@
from __future__ import unicode_literals
import logging
logger = logging.getLogger(__name__)
class ErrorLoggingMiddleware(object):
def process_exception(self, request, exception):
logger.exception(
'Exception caught by request middleware; %s, %s', request,
exception
)

View File

@@ -1,7 +1,9 @@
from __future__ import unicode_literals
import os
import tempfile
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from smart_settings import Namespace
@@ -40,3 +42,10 @@ setting_temporary_directory = namespace.add_setting(
),
is_path=True
)
setting_production_error_log_path = namespace.add_setting(
global_name='COMMON_PRODUCTION_ERROR_LOG_PATH',
default=os.path.join(settings.BASE_DIR, 'error.log'), help_text=_(
'Path to the logfile that will track errors during production.'
),
is_path=True
)

View File

@@ -37,6 +37,7 @@ class CheckVersionView(SimpleView):
template_name = 'appearance/generic_template.html'
def get_extra_context(self):
raise Exception('asd')
try:
check_version()
except NotLatestVersion as exception:

View File

@@ -108,6 +108,7 @@ INSTALLED_APPS = (
)
MIDDLEWARE_CLASSES = (
'common.middleware.error_logging.ErrorLoggingMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',