@@ -140,6 +140,12 @@ def log_message(self, format, *args):
140
140
"""Log nothing."""
141
141
142
142
143
+ class _PrintHandler (WSGIRequestHandler ):
144
+ """WSGI handler that print log requests to console."""
145
+
146
+ def log_message (self , format , * args ):
147
+ print (format % args )
148
+
143
149
class ThreadingWSGIServer (ThreadingMixIn , WSGIServer ):
144
150
"""Thread per request HTTP server."""
145
151
# Make worker threads "fire and forget". Beginning with Python 3.7 this
@@ -210,6 +216,7 @@ def start_wsgi_server(
210
216
client_capath : Optional [str ] = None ,
211
217
protocol : int = ssl .PROTOCOL_TLS_SERVER ,
212
218
client_auth_required : bool = False ,
219
+ debug : bool = False
213
220
) -> Tuple [WSGIServer , threading .Thread ]:
214
221
"""Starts a WSGI server for prometheus metrics as a daemon thread."""
215
222
@@ -218,7 +225,10 @@ class TmpServer(ThreadingWSGIServer):
218
225
219
226
TmpServer .address_family , addr = _get_best_family (addr , port )
220
227
app = make_wsgi_app (registry )
221
- httpd = make_server (addr , port , app , TmpServer , handler_class = _SilentHandler )
228
+ handler = _SilentHandler
229
+ if debug :
230
+ handler = _PrintHandler
231
+ httpd = make_server (addr , port , app , TmpServer , handler_class = handler )
222
232
if certfile and keyfile :
223
233
context = _get_ssl_ctx (certfile , keyfile , protocol , client_cafile , client_capath , client_auth_required )
224
234
httpd .socket = context .wrap_socket (httpd .socket , server_side = True )
0 commit comments