How to alter the logger format?

1. Severity of the issue: (select one)
Medium: Significantly affects my productivity but can find a workaround.

2. Environment:

  • Ray version: 2.58.0
  • Python version: 3.13.15
  • OS: Arch Linux

3. What happened vs. what you expected:

  • Expected: To be able to disable the (foo pid=123)-style prefixing to log messages.
  • Actual: I can’t seem to achieve this despite following Ray’s docs and Python’s logging module

Hi there, we have a fairly customized logging environment in our app, into which we are trying to integrate Ray. We format all of our messages as logfmt , but Ray insists on prepending every log message with process information like (foo pid=81717). I’d like to disable this completely. However, all my experiments have failed so far. I’m attempting things like this:

def configure_ray_logging() -> None:
    ray_logger = logging.getLogger("ray")
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter("%(message)s")
    ch.setFormatter(formatter)
    ray_logger.addHandler(ch)

if __name__ == "__main__":
    ray.init(runtime_env={"worker_process_setup_hook": configure_ray_logging})
    # etc.

But this has no effect. The Ray workers still prepend the process info, which conflicts with logfmt. It prints a message like this:

(foo pid=81717) ts=2026-09-25T10:52:47.003 level=INFO msg=\"Got: 0\" run_id=TDIO9HpDwzAaBULy-FAYi exec_name=default_worker parent_run_id=6o1AtAS3jur-qnmC3di9z

How can I fix this? Thank you.

Set the environment variable RAY_DISABLE_WORKER_LOG_PREFIX=1 before starting your Ray application to disable the (foo pid=123)-style prefix on worker logs. This will keep your log lines in logfmt or JSON format without Ray prepending process info, as confirmed in the official documentation and tests. Example:

import os
os.environ["RAY_DISABLE_WORKER_LOG_PREFIX"] = "1"
import ray
ray.init()

Note: This must be set before importing ray. If you also want to avoid log deduplication suffixes, set RAY_DEDUP_LOGS=0 as well. Your custom logging setup via worker_process_setup_hook does not affect the prefix; only the environment variable disables it.
Sources:

Hint: Mention @Herald in the post for followups.

@Herald This is frustrating because this isn’t mentioned in the official published documentation. It also doesn’t work for the currently published version of Ray.

EDIT: Hah, the feature was added two days after the current release was made.

See also a related issue on GH: [Core] Provide a way to disable the worker-log `(pid=…)` prefix without disabling driver forwarding or overriding the root logger · Issue #64992 · ray-project/ray · GitHub