From 467430dd550db1f5057ee47e2d8e5b174d248807 Mon Sep 17 00:00:00 2001 From: Eric Liang Date: Fri, 29 Jul 2022 10:55:15 -0700 Subject: [PATCH] Fix logger initialization (#27238) --- python/ray/_private/worker.py | 4 +--- python/ray/tests/test_output.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/python/ray/_private/worker.py b/python/ray/_private/worker.py index 7b2e48b87..f3b51f813 100644 --- a/python/ray/_private/worker.py +++ b/python/ray/_private/worker.py @@ -1165,7 +1165,7 @@ def init( arguments is passed in. """ if configure_logging: - setup_logger(logging_level, logging_format) + setup_logger(logging_level, logging_format or ray_constants.LOGGER_FORMAT) # Parse the hidden options: _enable_object_reconstruction: bool = kwargs.pop( @@ -1192,8 +1192,6 @@ def init( _node_name: str = kwargs.pop("_node_name", None) # Fix for https://github.com/ray-project/ray/issues/26729 _skip_env_hook: bool = kwargs.pop("_skip_env_hook", False) - if not logging_format: - logging_format = ray_constants.LOGGER_FORMAT # If available, use RAY_ADDRESS to override if the address was left # unspecified, or set to "auto" in the call to init diff --git a/python/ray/tests/test_output.py b/python/ray/tests/test_output.py index 3b1f3d916..d827bbbe7 100644 --- a/python/ray/tests/test_output.py +++ b/python/ray/tests/test_output.py @@ -14,6 +14,21 @@ from ray._private.test_utils import ( ) +def test_logger_config(): + script = """ +import ray + +ray.init(num_cpus=1) + """ + + proc = run_string_as_driver_nonblocking(script) + out_str = proc.stdout.read().decode("ascii") + err_str = proc.stderr.read().decode("ascii") + + print(out_str, err_str) + assert "INFO worker.py:" in err_str, err_str + + @pytest.mark.skipif(sys.platform == "win32", reason="Failing on Windows.") def test_spill_logs(): script = """