Issue with RAY_LOGGING_CONFIG_ENCODING="JSON" Environment Variable in Ray 2.40.0

Hi everyone,

First of all, thank you for creating such an amazing framework as Ray!

I came across the documentation Configure Logging with Ray, which mentions that I can configure the log format using the RAY_LOGGING_CONFIG_ENCODING environment variable. However, when I try running ray start with ENV RAY_LOGGING_CONFIG_ENCODING="JSON" inside a Docker container, I get the following error:

2025-01-23 18:02:47,540	ERROR server.py:134 -- Running Ray Init failed:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/ray/util/client/server/server.py", line 132, in Init
    self.ray_connect_handler(job_config, **extra_kwargs)
  File "/usr/local/lib/python3.10/site-packages/ray/util/client/server/server.py", line 834, in ray_connect_handler
    ray.init(address=address, job_config=job_config, **ray_init_kwargs)
  File "/usr/local/lib/python3.10/site-packages/ray/_private/client_mode_hook.py", line 103, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/ray/_private/worker.py", line 1450, in init
    logging_config = logging_config or LoggingConfig(
  File "<string>", line 5, in __init__
  File "/usr/local/lib/python3.10/site-packages/ray/_private/ray_logging/logging_config.py", line 88, in __post_init__
    raise ValueError(
ValueError: Invalid encoding type: JSON. Valid encoding types are: ['TEXT']

Could you please advise what might be missing in my configuration?

Environment Details:

  • Base image: python:3.10-slim
  • Installed packages:
    pydantic==2.10.5  
    ray[serve,data]==2.40.0  # data is for ray.workflow, serve is for ray.serve  
    python-json-logger==3.2.1  
    

Additionally, I noticed that JsonFormatter is declared in the Ray source code here: ray_logging/formatters.py#L92, but it’s not listed as an option in the encoding type dictionary here: ray_logging/logging_config.py#L27.

Was this intentional, or is JSON logging still experimental/not yet available in Ray 2.40.0?

Thank you for your help!

Hi levushkin, welcome to the Ray community!! I’m glad to hear you’re enjoying Ray :slight_smile:

For JSON logging, JSON logging can be configured using the LoggingConfig class in Ray Serve, which allows you to specify encoding=“JSON” when setting up logging for Ray Serve deployments. Here’s an example of how you can configure JSON logging for Ray Serve:

from ray import serve
from ray.serve.schema import LoggingConfig

@serve.deployment
class Model:
    def __call__(self) -> int:
        return "hello world"

serve.run(Model.bind(), logging_config=LoggingConfig(encoding="JSON"))

Here’s a few docs that mention it:

Sources:

Have you tried using the LoggingConfig class by any chance?