Skip to content

stdlib logging module doesn't work in test runner subprocesses #55266

@gsnedders

Description

@gsnedders

While we configure a mozlog logger, we don't configure any stdlib logger in the subprocess.

See:

# Ensure that when we start this in a new process we have the global lock
# in the logging module unlocked
release_mozlog_lock()
proc_name = mpcontext.get_context().current_process().name
logger = structuredlog.StructuredLogger(proc_name)
logger.add_handler(LogMessageHandler(send_message))

Something like this fixes it, but with a notable change:

diff --git a/tools/wptrunner/wptrunner/testrunner.py b/tools/wptrunner/wptrunner/testrunner.py
index cc81b73511..f0fd502e51 100644
--- a/tools/wptrunner/wptrunner/testrunner.py
+++ b/tools/wptrunner/wptrunner/testrunner.py
@@ -10,6 +10,7 @@ from typing import Any, Mapping, Optional
 
 from mozlog import structuredlog, capture
 
+from . import wptlogging
 from . import mpcontext, testloader
 
 # Special value used as a sentinal in various commands
@@ -199,8 +200,13 @@ def start_runner(runner_command_queue, runner_result_queue,
     release_mozlog_lock()
 
     proc_name = mpcontext.get_context().current_process().name
-    logger = structuredlog.StructuredLogger(proc_name)
+    logger = structuredlog.StructuredLogger("root")
     logger.add_handler(LogMessageHandler(send_message))
+    wptlogging.setup_stdlib_logger()
 
     with capture.CaptureIO(logger, capture_stdio):
         try:

This clearly changes the name of the logger (though hopefully the pid, etc., are all still correct?); this is needed because the wrapper uses the same name as the underlying stdlib logger:

UnstructuredHandler(
self.wrapped.name, logging.getLevelName(self.wrapped.level)
)

(I don't know if this is what #10450 was about; it's unclear what that was about, because I believe it's always worked in the main process?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    infrawptrunnerThe automated test runner, commonly called through ./wpt run

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions