From 0b4e09da762dda02260b82567ee257a1e89029f4 Mon Sep 17 00:00:00 2001 From: mehrdadn Date: Fri, 10 Apr 2020 16:41:21 -0700 Subject: [PATCH] Log to terminal if glog is also doing so (#7868) --- python/ray/node.py | 26 +++++++++++--------------- python/ray/services.py | 4 +++- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/python/ray/node.py b/python/ray/node.py index 226a74f3e..8a50ac7c3 100644 --- a/python/ray/node.py +++ b/python/ray/node.py @@ -349,25 +349,21 @@ class Node: raise FileExistsError(errno.EEXIST, "No usable temporary filename found") - def new_log_files(self, name, redirect_output=True): + def new_log_files(self, name): """Generate partially randomized filenames for log files. Args: name (str): descriptive string for this log file. - redirect_output (bool): True if files should be generated for - logging stdout and stderr and false if stdout and stderr - should not be redirected. - If it is None, it will use the "redirect_output" Ray parameter. Returns: - If redirect_output is true, this will return a tuple of two - file handles. The first is for redirecting stdout and the - second is for redirecting stderr. - If redirect_output is false, this will return a tuple - of two None objects. + A tuple of two file handles for redirecting (stdout, stderr). """ + redirect_output = self._ray_params.redirect_output + if redirect_output is None: - redirect_output = self._ray_params.redirect_output + # Make the default behavior match that of glog. + redirect_output = os.getenv("GLOG_logtostderr") != "1" + if not redirect_output: return None, None @@ -471,7 +467,7 @@ class Node: def start_reporter(self): """Start the reporter.""" - stdout_file, stderr_file = self.new_log_files("reporter", True) + stdout_file, stderr_file = self.new_log_files("reporter") process_info = ray.services.start_reporter( self.redis_address, stdout_file=stdout_file, @@ -492,7 +488,7 @@ class Node: fail to start the webui. Otherwise it will print a warning if we fail to start the webui. """ - stdout_file, stderr_file = self.new_log_files("dashboard", True) + stdout_file, stderr_file = self.new_log_files("dashboard") self._webui_url, process_info = ray.services.start_dashboard( require_webui, self._ray_params.webui_host, @@ -580,8 +576,8 @@ class Node: def new_worker_redirected_log_file(self, worker_id): """Create new logging files for workers to redirect its output.""" - worker_stdout_file, worker_stderr_file = (self.new_log_files( - "worker-" + ray.utils.binary_to_hex(worker_id), True)) + worker_stdout_file, worker_stderr_file = ( + self.new_log_files("worker-" + ray.utils.binary_to_hex(worker_id))) return worker_stdout_file, worker_stderr_file def start_worker(self): diff --git a/python/ray/services.py b/python/ray/services.py index 2d83729c2..8ac257da8 100644 --- a/python/ray/services.py +++ b/python/ray/services.py @@ -939,7 +939,9 @@ def _start_redis_instance(executable, if counter == num_retries: raise RuntimeError("Couldn't start Redis. " "Check log files: {} {}".format( - stdout_file.name, stderr_file.name)) + stdout_file.name if stdout_file is not None else + "", stderr_file.name + if stdout_file is not None else "")) # Create a Redis client just for configuring Redis. redis_client = redis.StrictRedis(