@@ -408,21 +408,20 @@ def log_request(
408408
409409 code = str (code )
410410
411- if _log_add_style :
412- if code [0 ] == "1" : # 1xx - Informational
413- msg = _ansi_style (msg , "bold" )
414- elif code == "200" : # 2xx - Success
415- pass
416- elif code == "304" : # 304 - Resource Not Modified
417- msg = _ansi_style (msg , "cyan" )
418- elif code [0 ] == "3" : # 3xx - Redirection
419- msg = _ansi_style (msg , "green" )
420- elif code == "404" : # 404 - Resource Not Found
421- msg = _ansi_style (msg , "yellow" )
422- elif code [0 ] == "4" : # 4xx - Client Error
423- msg = _ansi_style (msg , "bold" , "red" )
424- else : # 5xx, or any other response
425- msg = _ansi_style (msg , "bold" , "magenta" )
411+ if code [0 ] == "1" : # 1xx - Informational
412+ msg = _ansi_style (msg , "bold" )
413+ elif code == "200" : # 2xx - Success
414+ pass
415+ elif code == "304" : # 304 - Resource Not Modified
416+ msg = _ansi_style (msg , "cyan" )
417+ elif code [0 ] == "3" : # 3xx - Redirection
418+ msg = _ansi_style (msg , "green" )
419+ elif code == "404" : # 404 - Resource Not Found
420+ msg = _ansi_style (msg , "yellow" )
421+ elif code [0 ] == "4" : # 4xx - Client Error
422+ msg = _ansi_style (msg , "bold" , "red" )
423+ else : # 5xx, or any other response
424+ msg = _ansi_style (msg , "bold" , "magenta" )
426425
427426 self .log ("info" , '"%s" %s %s' , msg , code , size )
428427
@@ -441,6 +440,9 @@ def log(self, type: str, message: str, *args: t.Any) -> None:
441440
442441
443442def _ansi_style (value : str , * styles : str ) -> str :
443+ if not _log_add_style :
444+ return value
445+
444446 codes = {
445447 "bold" : 1 ,
446448 "red" : 31 ,
@@ -752,36 +754,37 @@ def handle_error(
752754
753755 def log_startup (self ) -> None :
754756 """Show information about the address when starting the server."""
757+ dev_warning = (
758+ "WARNING: This is a development server. Do not use it in a production"
759+ " deployment. Use a production WSGI server instead."
760+ )
761+ dev_warning = _ansi_style (dev_warning , "bold" , "red" )
762+ messages = [dev_warning ]
763+
755764 if self .address_family == af_unix :
756- _log ( "info" , f" * Running on { self .host } (Press CTRL+C to quit) " )
765+ messages . append ( f" * Running on { self .host } " )
757766 else :
758767 scheme = "http" if self .ssl_context is None else "https"
759- messages = []
760- all_addresses_message = (
761- f" * Running on all addresses ({ self .host } )\n "
762- " WARNING: This is a development server. Do not use it in"
763- " a production deployment."
764- )
768+ display_hostname = self .host
765769
766- if self .host == "0.0.0.0" :
767- messages .append (all_addresses_message )
768- messages .append (f" * Running on { scheme } ://127.0.0.1:{ self .port } " )
769- display_hostname = get_interface_ip (socket .AF_INET )
770- elif self .host == "::" :
771- messages .append (all_addresses_message )
772- messages .append (f" * Running on { scheme } ://[::1]:{ self .port } " )
773- display_hostname = get_interface_ip (socket .AF_INET6 )
774- else :
775- display_hostname = self .host
770+ if self .host in {"0.0.0.0" , "::" }:
771+ messages .append (f" * Running on all addresses ({ self .host } )" )
772+
773+ if self .host == "0.0.0.0" :
774+ localhost = "127.0.0.1"
775+ display_hostname = get_interface_ip (socket .AF_INET )
776+ else :
777+ localhost = "[::1]"
778+ display_hostname = get_interface_ip (socket .AF_INET6 )
779+
780+ messages .append (f" * Running on { scheme } ://{ localhost } :{ self .port } " )
776781
777782 if ":" in display_hostname :
778783 display_hostname = f"[{ display_hostname } ]"
779784
780- messages .append (
781- f" * Running on { scheme } ://{ display_hostname } :{ self .port } "
782- " (Press CTRL+C to quit)"
783- )
784- _log ("info" , "\n " .join (messages ))
785+ messages .append (f" * Running on { scheme } ://{ display_hostname } :{ self .port } " )
786+
787+ _log ("info" , "\n " .join (messages ))
785788
786789
787790class ThreadedWSGIServer (socketserver .ThreadingMixIn , BaseWSGIServer ):
@@ -1076,6 +1079,7 @@ def run_simple(
10761079
10771080 if not is_running_from_reloader ():
10781081 srv .log_startup ()
1082+ _log ("info" , _ansi_style ("Press CTRL+C to quit" , "yellow" ))
10791083
10801084 if use_reloader :
10811085 from ._reloader import run_with_reloader
0 commit comments