Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 6e7ac6d

Browse files
Hexclesjgraham
authored andcommitted
Fix pywebsocket logging properly
The previous attempt (#17124) called pywebsocket._configure_logging, which had the unwanted side effect of resetting lots of logging setup in the pywebsocket subprocess (e.g. mozlog configured by wptrunner -- the log messages produced by pywebsocket lost its structure and became a simple STDERR text captured by mozlog.capture). Instead of calling pywebsocket._configure_logging, the original issue (log level in config.json not honoured by pywebsocket) should be fixed by setting the log level on the root logger instead, which will set up all loggers (including those in third-party libraries) correctly. This is done only on the entry point of `wpt serve` and won't affect wptrunner which has its own logging setup.
1 parent b693b1b commit 6e7ac6d

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

tools/serve/serve.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def _script_replacement(self, key, value):
309309

310310
rewrites = [("GET", "/resources/WebIDLParser.js", "/resources/webidl2/lib/webidl2.js")]
311311

312+
312313
class RoutesBuilder(object):
313314
def __init__(self):
314315
self.forbidden_override = [("GET", "/tools/runner/*", handlers.file_handler),
@@ -502,7 +503,7 @@ def make_hosts_file(config, host):
502503
def start_servers(host, ports, paths, routes, bind_address, config, **kwargs):
503504
servers = defaultdict(list)
504505
for scheme, ports in ports.items():
505-
assert len(ports) == {"http":2}.get(scheme, 1)
506+
assert len(ports) == {"http": 2}.get(scheme, 1)
506507

507508
# If trying to start HTTP/2.0 server, check compatibility
508509
if scheme == 'http2' and not http2_compatible():
@@ -513,11 +514,11 @@ def start_servers(host, ports, paths, routes, bind_address, config, **kwargs):
513514
for port in ports:
514515
if port is None:
515516
continue
516-
init_func = {"http":start_http_server,
517-
"https":start_https_server,
518-
"http2":start_http2_server,
519-
"ws":start_ws_server,
520-
"wss":start_wss_server}[scheme]
517+
init_func = {"http": start_http_server,
518+
"https": start_https_server,
519+
"http2": start_http2_server,
520+
"ws": start_ws_server,
521+
"wss": start_wss_server}[scheme]
521522

522523
server_proc = ServerProc(scheme=scheme)
523524
server_proc.start(init_func, host, port, paths, routes, bind_address,
@@ -571,14 +572,14 @@ def start_http2_server(host, port, paths, routes, bind_address, config, **kwargs
571572
encrypt_after_connect=config.ssl_config["encrypt_after_connect"],
572573
latency=kwargs.get("latency"),
573574
http2=True)
575+
576+
574577
class WebSocketDaemon(object):
575-
def __init__(self, host, port, doc_root, handlers_root, log_level, bind_address,
576-
ssl_config):
578+
def __init__(self, host, port, doc_root, handlers_root, bind_address, ssl_config):
577579
self.host = host
578580
cmd_args = ["-p", port,
579581
"-d", doc_root,
580-
"-w", handlers_root,
581-
"--log-level", log_level]
582+
"-w", handlers_root]
582583

583584
if ssl_config is not None:
584585
# This is usually done through pywebsocket.main, however we're
@@ -656,9 +657,8 @@ def start_ws_server(host, port, paths, routes, bind_address, config, **kwargs):
656657
str(port),
657658
repo_root,
658659
config.paths["ws_doc_root"],
659-
"debug",
660660
bind_address,
661-
ssl_config = None)
661+
ssl_config=None)
662662

663663

664664
def start_wss_server(host, port, paths, routes, bind_address, config, **kwargs):
@@ -670,7 +670,6 @@ def start_wss_server(host, port, paths, routes, bind_address, config, **kwargs):
670670
str(port),
671671
repo_root,
672672
config.paths["ws_doc_root"],
673-
"debug",
674673
bind_address,
675674
config.ssl_config)
676675

@@ -727,9 +726,11 @@ def build_config(override_path=None, **kwargs):
727726

728727
return rv
729728

729+
730730
def _make_subdomains_product(s, depth=2):
731731
return {u".".join(x) for x in chain(*(product(s, repeat=i) for i in range(1, depth+1)))}
732732

733+
733734
_subdomains = {u"www",
734735
u"www1",
735736
u"www2",
@@ -746,7 +747,8 @@ def _make_subdomains_product(s, depth=2):
746747
class ConfigBuilder(config.ConfigBuilder):
747748
"""serve config
748749
749-
this subclasses wptserve.config.ConfigBuilder to add serve config options"""
750+
This subclasses wptserve.config.ConfigBuilder to add serve config options.
751+
"""
750752

751753
_default = {
752754
"browser_host": "web-platform.test",
@@ -840,6 +842,8 @@ def run(**kwargs):
840842
global logger
841843
logger = config.logger
842844
set_logger(logger)
845+
# Configure the root logger to cover third-party libraries.
846+
logging.getLogger().setLevel(config.log_level)
843847

844848
def handle_signal(signum, frame):
845849
logger.debug("Received signal %s. Shutting down.", signum)

0 commit comments

Comments
 (0)