##// END OF EJS Templates
debugging: expose logs/exception when debug log is enabled.
super-admin -
r4768:f604047c default
parent child Browse files
Show More
@@ -154,6 +154,7 b' def not_found_view(request):'
154 def error_handler(exception, request):
154 def error_handler(exception, request):
155 import rhodecode
155 import rhodecode
156 from rhodecode.lib import helpers
156 from rhodecode.lib import helpers
157 from rhodecode.lib.utils2 import str2bool
157
158
158 rhodecode_title = rhodecode.CONFIG.get('rhodecode_title') or 'RhodeCode'
159 rhodecode_title = rhodecode.CONFIG.get('rhodecode_title') or 'RhodeCode'
159
160
@@ -205,6 +206,8 b' def error_handler(exception, request):'
205
206
206 if c.show_exception_id:
207 if c.show_exception_id:
207 store_exception(c.exception_id, exc_info)
208 store_exception(c.exception_id, exc_info)
209 c.exception_debug = str2bool(rhodecode.CONFIG.get('debug'))
210 c.exception_config_ini = rhodecode.CONFIG.get('__file__')
208
211
209 response = render_to_response(
212 response = render_to_response(
210 '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request,
213 '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request,
@@ -125,20 +125,34 b' class ColorFormatter(ExceptionAwareForma'
125
125
126 def _inject_req_id(record):
126 def _inject_req_id(record):
127 from pyramid.threadlocal import get_current_request
127 from pyramid.threadlocal import get_current_request
128 dummy = '00000000-0000-0000-0000-000000000000'
129 req_id = None
130
128 req = get_current_request()
131 req = get_current_request()
129 dummy = '00000000-0000-0000-0000-000000000000'
132 if req:
130 req_id = 'req_id:%-36s' % (getattr(req, 'req_id', dummy))
133 req_id = getattr(req, 'req_id', None)
134
135 req_id = 'req_id:%-36s' % (req_id or dummy)
131 record.req_id = req_id
136 record.req_id = req_id
132
137
133
138
139 def _add_log_to_debug_bucket(formatted_record):
140 from pyramid.threadlocal import get_current_request
141 req = get_current_request()
142 if req:
143 req.req_id_bucket.append(formatted_record)
144
145
134 class RequestTrackingFormatter(ExceptionAwareFormatter):
146 class RequestTrackingFormatter(ExceptionAwareFormatter):
135 def format(self, record):
147 def format(self, record):
136 _inject_req_id(record)
148 _inject_req_id(record)
137 def_record = logging.Formatter.format(self, record)
149 def_record = logging.Formatter.format(self, record)
150 _add_log_to_debug_bucket(def_record)
138 return def_record
151 return def_record
139
152
140
153
141 class ColorRequestTrackingFormatter(ColorFormatter):
154 class ColorRequestTrackingFormatter(ColorFormatter):
155
142 def format(self, record):
156 def format(self, record):
143 """
157 """
144 Changes record's levelname to use with COLORS enum
158 Changes record's levelname to use with COLORS enum
@@ -150,6 +164,7 b' class ColorRequestTrackingFormatter(Colo'
150 end = RESET_SEQ
164 end = RESET_SEQ
151
165
152 colored_record = ''.join([start, def_record, end])
166 colored_record = ''.join([start, def_record, end])
167 _add_log_to_debug_bucket(def_record)
153 return colored_record
168 return colored_record
154
169
155
170
@@ -24,6 +24,15 b' from pyramid.request import Request as _'
24
24
25
25
26 class Request(_Request):
26 class Request(_Request):
27 _req_id_bucket = list()
28
27 @reify
29 @reify
28 def req_id(self):
30 def req_id(self):
29 return str(uuid4())
31 return str(uuid4())
32
33 @property
34 def req_id_bucket(self):
35 return self._req_id_bucket
36
37 def req_id_records_init(self):
38 self._req_id_bucket = list()
@@ -106,6 +106,14 b' def add_request_user_context(event):'
106 request.environ['rc_req_id'] = req_id
106 request.environ['rc_req_id'] = req_id
107
107
108
108
109 def reset_log_bucket(event):
110 """
111 reset the log bucket on new request
112 """
113 request = event.request
114 request.req_id_records_init()
115
116
109 def scan_repositories_if_enabled(event):
117 def scan_repositories_if_enabled(event):
110 """
118 """
111 This is subscribed to the `pyramid.events.ApplicationCreated` event. It
119 This is subscribed to the `pyramid.events.ApplicationCreated` event. It
@@ -84,6 +84,24 b''
84
84
85 Super-admins can see details of the above error in the exception tracker found under
85 Super-admins can see details of the above error in the exception tracker found under
86 <a href="${h.route_url('admin_settings_exception_tracker')}">admin > settings > exception tracker</a>.
86 <a href="${h.route_url('admin_settings_exception_tracker')}">admin > settings > exception tracker</a>.
87
88 % if c.exception_debug:
89 <pre>
90 <strong>DEBUG MODE ON FOR EXCEPTION: ${c.exception_id}</strong>
91 <strong>REQUEST_ID: ${getattr(request, 'req_id', None)}</strong>
92 ----------------
93 debug mode is controlled by
94 ${c.exception_config_ini}
95 file settings:
96
97 debug = true
98 ----------------
99
100 % for rec in getattr(request, 'req_id_bucket', []):
101 ${rec}
102 % endfor
103 </pre>
104 % endif
87 </p>
105 </p>
88 </div>
106 </div>
89 % endif
107 % endif
@@ -112,6 +112,8 b' def includeme(config):'
112 'pyramid.events.NewRequest')
112 'pyramid.events.NewRequest')
113 config.add_subscriber('rhodecode.subscribers.add_localizer',
113 config.add_subscriber('rhodecode.subscribers.add_localizer',
114 'pyramid.events.NewRequest')
114 'pyramid.events.NewRequest')
115 config.add_subscriber('rhodecode.subscribers.reset_log_bucket',
116 'pyramid.events.NewRequest')
115 config.add_subscriber('rhodecode.subscribers.add_request_user_context',
117 config.add_subscriber('rhodecode.subscribers.add_request_user_context',
116 'pyramid.events.ContextFound')
118 'pyramid.events.ContextFound')
117 config.add_tween('rhodecode.tweens.vcs_detection_tween_factory')
119 config.add_tween('rhodecode.tweens.vcs_detection_tween_factory')
General Comments 0
You need to be logged in to leave comments. Login now