debugging: expose logs/exception when debug log is enabled.
This commit is contained in:
parent
d26e0145a1
commit
227f4040d2
6 changed files with 57 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -125,20 +125,34 @@ class ColorFormatter(ExceptionAwareFormatter):
|
|||
|
||||
def _inject_req_id(record):
|
||||
from pyramid.threadlocal import get_current_request
|
||||
req = get_current_request()
|
||||
dummy = '00000000-0000-0000-0000-000000000000'
|
||||
req_id = 'req_id:%-36s' % (getattr(req, 'req_id', dummy))
|
||||
req_id = None
|
||||
|
||||
req = get_current_request()
|
||||
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(ColorFormatter):
|
|||
end = RESET_SEQ
|
||||
|
||||
colored_record = ''.join([start, def_record, end])
|
||||
_add_log_to_debug_bucket(def_record)
|
||||
return colored_record
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,15 @@ from pyramid.request import Request as _Request
|
|||
|
||||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -84,6 +84,24 @@
|
|||
|
||||
Super-admins can see details of the above error in the exception tracker found under
|
||||
<a href="${h.route_url('admin_settings_exception_tracker')}">admin > settings > exception tracker</a>.
|
||||
|
||||
% if c.exception_debug:
|
||||
<pre>
|
||||
<strong>DEBUG MODE ON FOR EXCEPTION: ${c.exception_id}</strong>
|
||||
<strong>REQUEST_ID: ${getattr(request, 'req_id', None)}</strong>
|
||||
----------------
|
||||
debug mode is controlled by
|
||||
${c.exception_config_ini}
|
||||
file settings:
|
||||
|
||||
debug = true
|
||||
----------------
|
||||
|
||||
% for rec in getattr(request, 'req_id_bucket', []):
|
||||
${rec}
|
||||
% endfor
|
||||
</pre>
|
||||
% endif
|
||||
</p>
|
||||
</div>
|
||||
% endif
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue