diff --git a/python/ray/serve/_private/api.py b/python/ray/serve/_private/api.py index f180b7f4470f..0e4d25188fb6 100644 --- a/python/ray/serve/_private/api.py +++ b/python/ray/serve/_private/api.py @@ -14,6 +14,7 @@ HTTP_PROXY_TIMEOUT, RAY_SERVE_ENABLE_TASK_EVENTS, SERVE_CONTROLLER_NAME, + SERVE_LOGGER_NAME, SERVE_NAMESPACE, ) from ray.serve._private.controller import ServeController @@ -23,7 +24,7 @@ from ray.serve.exceptions import RayServeException from ray.serve.schema import LoggingConfig -logger = logging.getLogger(__file__) +logger = logging.getLogger(SERVE_LOGGER_NAME) def get_deployment(name: str, app_name: str = ""): diff --git a/python/ray/serve/_private/client.py b/python/ray/serve/_private/client.py index 114ee813f160..f6ff6e361922 100644 --- a/python/ray/serve/_private/client.py +++ b/python/ray/serve/_private/client.py @@ -20,6 +20,7 @@ CLIENT_POLLING_INTERVAL_S, MAX_CACHED_HANDLES, SERVE_DEFAULT_APP_NAME, + SERVE_LOGGER_NAME, ) from ray.serve._private.controller import ServeController from ray.serve._private.deploy_utils import get_deploy_args @@ -34,7 +35,7 @@ from ray.serve.handle import DeploymentHandle, _HandleOptions from ray.serve.schema import LoggingConfig, ServeApplicationSchema, ServeDeploySchema -logger = logging.getLogger(__file__) +logger = logging.getLogger(SERVE_LOGGER_NAME) def _ensure_connected(f: Callable) -> Callable: diff --git a/python/ray/serve/context.py b/python/ray/serve/context.py index 739d1f20077d..5fc7b0cc72a7 100644 --- a/python/ray/serve/context.py +++ b/python/ray/serve/context.py @@ -13,12 +13,16 @@ from ray.serve._private.client import ServeControllerClient from ray.serve._private.common import ReplicaID from ray.serve._private.config import DeploymentConfig -from ray.serve._private.constants import SERVE_CONTROLLER_NAME, SERVE_NAMESPACE +from ray.serve._private.constants import ( + SERVE_CONTROLLER_NAME, + SERVE_LOGGER_NAME, + SERVE_NAMESPACE, +) from ray.serve.exceptions import RayServeException from ray.serve.grpc_util import RayServegRPCContext from ray.util.annotations import DeveloperAPI -logger = logging.getLogger(__file__) +logger = logging.getLogger(SERVE_LOGGER_NAME) _INTERNAL_REPLICA_CONTEXT: "ReplicaContext" = None _global_client: ServeControllerClient = None diff --git a/python/ray/serve/gradio_integrations.py b/python/ray/serve/gradio_integrations.py index 3ec12cce5307..dc8960d78c8b 100644 --- a/python/ray/serve/gradio_integrations.py +++ b/python/ray/serve/gradio_integrations.py @@ -2,6 +2,7 @@ from typing import Callable from ray import serve +from ray.serve._private.constants import SERVE_LOGGER_NAME from ray.serve._private.http_util import ASGIAppReplicaWrapper from ray.util.annotations import PublicAPI @@ -11,7 +12,7 @@ print("Gradio isn't installed. Run `pip install gradio` to install Gradio.") raise -logger = logging.getLogger(__file__) +logger = logging.getLogger(SERVE_LOGGER_NAME) @PublicAPI(stability="alpha") diff --git a/python/ray/serve/tests/test_standalone_3.py b/python/ray/serve/tests/test_standalone_3.py index 8273c813d20c..b10342eafa18 100644 --- a/python/ray/serve/tests/test_standalone_3.py +++ b/python/ray/serve/tests/test_standalone_3.py @@ -1,3 +1,4 @@ +import logging import os import subprocess import sys @@ -15,7 +16,7 @@ from ray.cluster_utils import AutoscalingCluster, Cluster from ray.exceptions import RayActorError from ray.serve._private.common import ProxyStatus -from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME +from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME, SERVE_LOGGER_NAME from ray.serve._private.logging_utils import get_serve_logs_dir from ray.serve._private.utils import get_head_node_id from ray.serve.context import _get_global_client @@ -595,6 +596,17 @@ def test_client_shutdown_gracefully_when_timeout( log timeout message and exit the process. The controller will continue to shutdown everything gracefully. """ + logger = logging.getLogger(SERVE_LOGGER_NAME) + caplog.set_level(logging.WARNING, logger=SERVE_LOGGER_NAME) + + warning_msg = [] + + class WarningHandler(logging.Handler): + def emit(self, record): + warning_msg.append(self.format(record)) + + logger.addHandler(WarningHandler()) + # Setup a cluster with 2 nodes cluster = Cluster() cluster.add_node() @@ -621,7 +633,7 @@ def __call__(self): client.shutdown(timeout_s=timeout_s) assert ( f"Controller failed to shut down within {timeout_s}s. " - f"Check controller logs for more details." in caplog.text + f"Check controller logs for more details." in warning_msg ) # Ensure the all resources are shutdown gracefully.