mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 14:48:54 +08:00
Separate python logger module-wise (#2703)
## What do these changes do? 1. Separate the log related code to logger.py from services.py. 2. Allow users to modify logging formatter in `ray start`. ## Related issue number https://github.com/ray-project/ray/pull/2664
This commit is contained in:
committed by
Robert Nishihara
parent
26d3c0655c
commit
0b6e08ebee
@@ -4,6 +4,7 @@ from __future__ import print_function
|
||||
|
||||
import click
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
@@ -11,6 +12,7 @@ import ray.services as services
|
||||
from ray.autoscaler.commands import (attach_cluster, exec_cluster,
|
||||
create_or_update_cluster, rsync,
|
||||
teardown_cluster, get_head_node_ip)
|
||||
import ray.ray_constants as ray_constants
|
||||
import ray.utils
|
||||
|
||||
|
||||
@@ -149,20 +151,36 @@ def cli():
|
||||
is_flag=True,
|
||||
default=None,
|
||||
help="use the raylet code path")
|
||||
@click.option(
|
||||
"--logging-level",
|
||||
required=False,
|
||||
default=ray_constants.LOGGER_LEVEL,
|
||||
type=str,
|
||||
help=ray_constants.LOGGER_LEVEL_HELP)
|
||||
@click.option(
|
||||
"--logging-format",
|
||||
required=False,
|
||||
default=ray_constants.LOGGER_FORMAT,
|
||||
type=str,
|
||||
help=ray_constants.LOGGER_FORMAT_HELP)
|
||||
def start(node_ip_address, redis_address, redis_port, num_redis_shards,
|
||||
redis_max_clients, redis_shard_ports, object_manager_port,
|
||||
object_store_memory, num_workers, num_cpus, num_gpus, resources,
|
||||
head, no_ui, block, plasma_directory, huge_pages, autoscaling_config,
|
||||
use_raylet):
|
||||
use_raylet, logging_level, logging_format):
|
||||
# Convert hostnames to numerical IP address.
|
||||
if node_ip_address is not None:
|
||||
node_ip_address = services.address_to_ip(node_ip_address)
|
||||
if redis_address is not None:
|
||||
redis_address = services.address_to_ip(redis_address)
|
||||
|
||||
level = logging.getLevelName(logging_level.upper())
|
||||
logging.basicConfig(level=level, format=logging_format)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if use_raylet is None and os.environ.get("RAY_USE_XRAY") == "1":
|
||||
# This environment variable is used in our testing setup.
|
||||
print("Detected environment variable 'RAY_USE_XRAY'.")
|
||||
logger.info("Detected environment variable 'RAY_USE_XRAY'.")
|
||||
use_raylet = True
|
||||
|
||||
try:
|
||||
@@ -204,7 +222,8 @@ def start(node_ip_address, redis_address, redis_port, num_redis_shards,
|
||||
# Get the node IP address if one is not provided.
|
||||
if node_ip_address is None:
|
||||
node_ip_address = services.get_node_ip_address()
|
||||
print("Using IP address {} for this node.".format(node_ip_address))
|
||||
logger.info("Using IP address {} for this node."
|
||||
.format(node_ip_address))
|
||||
|
||||
address_info = {}
|
||||
# Use the provided object manager port if there is one.
|
||||
@@ -232,19 +251,20 @@ def start(node_ip_address, redis_address, redis_port, num_redis_shards,
|
||||
huge_pages=huge_pages,
|
||||
autoscaling_config=autoscaling_config,
|
||||
use_raylet=use_raylet)
|
||||
print(address_info)
|
||||
print("\nStarted Ray on this node. You can add additional nodes to "
|
||||
"the cluster by calling\n\n"
|
||||
" ray start --redis-address {}\n\n"
|
||||
"from the node you wish to add. You can connect a driver to the "
|
||||
"cluster from Python by running\n\n"
|
||||
" import ray\n"
|
||||
" ray.init(redis_address=\"{}\")\n\n"
|
||||
"If you have trouble connecting from a different machine, check "
|
||||
"that your firewall is configured properly. If you wish to "
|
||||
"terminate the processes that have been started, run\n\n"
|
||||
" ray stop".format(address_info["redis_address"],
|
||||
address_info["redis_address"]))
|
||||
logger.info(address_info)
|
||||
logger.info(
|
||||
"\nStarted Ray on this node. You can add additional nodes to "
|
||||
"the cluster by calling\n\n"
|
||||
" ray start --redis-address {}\n\n"
|
||||
"from the node you wish to add. You can connect a driver to the "
|
||||
"cluster from Python by running\n\n"
|
||||
" import ray\n"
|
||||
" ray.init(redis_address=\"{}\")\n\n"
|
||||
"If you have trouble connecting from a different machine, check "
|
||||
"that your firewall is configured properly. If you wish to "
|
||||
"terminate the processes that have been started, run\n\n"
|
||||
" ray stop".format(address_info["redis_address"],
|
||||
address_info["redis_address"]))
|
||||
else:
|
||||
# Start Ray on a non-head node.
|
||||
if redis_port is not None:
|
||||
@@ -281,7 +301,8 @@ def start(node_ip_address, redis_address, redis_port, num_redis_shards,
|
||||
# Get the node IP address if one is not provided.
|
||||
if node_ip_address is None:
|
||||
node_ip_address = services.get_node_ip_address(redis_address)
|
||||
print("Using IP address {} for this node.".format(node_ip_address))
|
||||
logger.info("Using IP address {} for this node."
|
||||
.format(node_ip_address))
|
||||
# Check that there aren't already Redis clients with the same IP
|
||||
# address connected with this Redis instance. This raises an exception
|
||||
# if the Redis server already has clients on this node.
|
||||
@@ -299,10 +320,10 @@ def start(node_ip_address, redis_address, redis_port, num_redis_shards,
|
||||
plasma_directory=plasma_directory,
|
||||
huge_pages=huge_pages,
|
||||
use_raylet=use_raylet)
|
||||
print(address_info)
|
||||
print("\nStarted Ray on this node. If you wish to terminate the "
|
||||
"processes that have been started, run\n\n"
|
||||
" ray stop")
|
||||
logger.info(address_info)
|
||||
logger.info("\nStarted Ray on this node. If you wish to terminate the "
|
||||
"processes that have been started, run\n\n"
|
||||
" ray stop")
|
||||
|
||||
if block:
|
||||
import time
|
||||
|
||||
Reference in New Issue
Block a user