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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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)
|
||||
==================
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
13
mayan/apps/common/middleware/error_logging.py
Normal file
13
mayan/apps/common/middleware/error_logging.py
Normal 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
|
||||
)
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user