How to redirect the log of ray server to the specified directory?

I deployed the Deployment on the ray server through python, but the logs in the Deployment only exist in the ServerController process, what should I do to redirect the logs to a directory I specify.

@839576266 we don’t currently have a way to redirect the logs to another directory, but you could configure your own logger inside each Deployment using Python’s logging library.

By the way, the logs are also available on disk in /tmp/ray/session_latest/logs/ (look for the worker log files).

I tried to configure logging in deployment, but the log is not output to the specified file, is there something wrong with my configuration?

import logging
import time

import ray
from ray import serve

logging.basicConfig(filename='/home/hwd/' + "c" + '.log',
                    format='[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]', level=logging.DEBUG,
                    filemode='a', datefmt='%Y-%m-%d%I:%M:%S %p')

environment_dict = {
    "working_dir": "/home/hwd/hik_kernel"
}

ray.init(address='ray://10.3.70.138:10001', runtime_env=environment_dict)

http_dict = {"host": "10.3.70.138", "port": 9009}
serve.start(http_options=http_dict)


@serve.deployment
def hello(request):
    name = request.query_params["name"]
    logging.info("print info")
    return f"Hello {name}!"


# Deploy model.
info = hello.options(num_replicas=3).deploy()
while True:
    time.sleep(5) 

I’m not completely sure, you might need to add a logging handler explicitly.

Can you try using that logging config in a simple local python program to see if it is a serve-specific issue?

I use the same method to execute the python script to output the log to the specified directory, but it doesn’t seem to work in the ray server.

@839576266 can you try running the logging.basicConfig line inside of the deployment (e.g., use a class and run it in the constructor).