@@ -140,6 +140,12 @@ def log_message(self, format, *args):
140140 """Log nothing."""
141141
142142
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+
143149class ThreadingWSGIServer (ThreadingMixIn , WSGIServer ):
144150 """Thread per request HTTP server."""
145151 # Make worker threads "fire and forget". Beginning with Python 3.7 this
@@ -210,6 +216,7 @@ def start_wsgi_server(
210216 client_capath : Optional [str ] = None ,
211217 protocol : int = ssl .PROTOCOL_TLS_SERVER ,
212218 client_auth_required : bool = False ,
219+ debug : bool = False
213220) -> Tuple [WSGIServer , threading .Thread ]:
214221 """Starts a WSGI server for prometheus metrics as a daemon thread."""
215222
@@ -218,7 +225,10 @@ class TmpServer(ThreadingWSGIServer):
218225
219226 TmpServer .address_family , addr = _get_best_family (addr , port )
220227 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 )
222232 if certfile and keyfile :
223233 context = _get_ssl_ctx (certfile , keyfile , protocol , client_cafile , client_capath , client_auth_required )
224234 httpd .socket = context .wrap_socket (httpd .socket , server_side = True )
0 commit comments