diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -154,6 +154,7 @@ def not_found_view(request): def error_handler(exception, request): import rhodecode from rhodecode.lib import helpers + from rhodecode.lib.utils2 import str2bool rhodecode_title = rhodecode.CONFIG.get('rhodecode_title') or 'RhodeCode' @@ -205,6 +206,8 @@ def error_handler(exception, request): if c.show_exception_id: store_exception(c.exception_id, exc_info) + c.exception_debug = str2bool(rhodecode.CONFIG.get('debug')) + c.exception_config_ini = rhodecode.CONFIG.get('__file__') response = render_to_response( '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request, diff --git a/rhodecode/lib/logging_formatter.py b/rhodecode/lib/logging_formatter.py --- a/rhodecode/lib/logging_formatter.py +++ b/rhodecode/lib/logging_formatter.py @@ -125,20 +125,34 @@ class ColorFormatter(ExceptionAwareForma def _inject_req_id(record): from pyramid.threadlocal import get_current_request + dummy = '00000000-0000-0000-0000-000000000000' + req_id = None + req = get_current_request() - dummy = '00000000-0000-0000-0000-000000000000' - req_id = 'req_id:%-36s' % (getattr(req, 'req_id', dummy)) + if req: + req_id = getattr(req, 'req_id', None) + + req_id = 'req_id:%-36s' % (req_id or dummy) record.req_id = req_id +def _add_log_to_debug_bucket(formatted_record): + from pyramid.threadlocal import get_current_request + req = get_current_request() + if req: + req.req_id_bucket.append(formatted_record) + + class RequestTrackingFormatter(ExceptionAwareFormatter): def format(self, record): _inject_req_id(record) def_record = logging.Formatter.format(self, record) + _add_log_to_debug_bucket(def_record) return def_record class ColorRequestTrackingFormatter(ColorFormatter): + def format(self, record): """ Changes record's levelname to use with COLORS enum @@ -150,6 +164,7 @@ class ColorRequestTrackingFormatter(Colo end = RESET_SEQ colored_record = ''.join([start, def_record, end]) + _add_log_to_debug_bucket(def_record) return colored_record diff --git a/rhodecode/lib/request.py b/rhodecode/lib/request.py --- a/rhodecode/lib/request.py +++ b/rhodecode/lib/request.py @@ -24,6 +24,15 @@ from pyramid.request import Request as _ class Request(_Request): + _req_id_bucket = list() + @reify def req_id(self): return str(uuid4()) + + @property + def req_id_bucket(self): + return self._req_id_bucket + + def req_id_records_init(self): + self._req_id_bucket = list() diff --git a/rhodecode/subscribers.py b/rhodecode/subscribers.py --- a/rhodecode/subscribers.py +++ b/rhodecode/subscribers.py @@ -106,6 +106,14 @@ def add_request_user_context(event): request.environ['rc_req_id'] = req_id +def reset_log_bucket(event): + """ + reset the log bucket on new request + """ + request = event.request + request.req_id_records_init() + + def scan_repositories_if_enabled(event): """ This is subscribed to the `pyramid.events.ApplicationCreated` event. It diff --git a/rhodecode/templates/errors/error_document.mako b/rhodecode/templates/errors/error_document.mako --- a/rhodecode/templates/errors/error_document.mako +++ b/rhodecode/templates/errors/error_document.mako @@ -84,6 +84,24 @@ Super-admins can see details of the above error in the exception tracker found under admin > settings > exception tracker. + +% if c.exception_debug: +
+DEBUG MODE ON FOR EXCEPTION: ${c.exception_id}
+REQUEST_ID: ${getattr(request, 'req_id', None)}
+----------------
+debug mode is controlled by
+${c.exception_config_ini}
+file settings:
+
+    debug = true
+----------------
+
+% for rec in getattr(request, 'req_id_bucket', []):
+${rec}
+% endfor
+
+% endif

% endif diff --git a/rhodecode/tweens.py b/rhodecode/tweens.py --- a/rhodecode/tweens.py +++ b/rhodecode/tweens.py @@ -112,6 +112,8 @@ def includeme(config): 'pyramid.events.NewRequest') config.add_subscriber('rhodecode.subscribers.add_localizer', 'pyramid.events.NewRequest') + config.add_subscriber('rhodecode.subscribers.reset_log_bucket', + 'pyramid.events.NewRequest') config.add_subscriber('rhodecode.subscribers.add_request_user_context', 'pyramid.events.ContextFound') config.add_tween('rhodecode.tweens.vcs_detection_tween_factory')