mirror of
https://github.com/wassname/ray.git
synced 2026-07-21 12:50:45 +08:00
[Logging] Log rotation on all components (#12101)
* In Progress. * Done. * Fix the issue. * Add wait for condition because logs are not written right away now. * debug string. * lint. * Fix flaky test. * Fix issues. * Fix test. * lint.
This commit is contained in:
@@ -25,6 +25,36 @@ def setup_logger(logging_level, logging_format):
|
||||
logger.propagate = False
|
||||
|
||||
|
||||
def setup_component_logger(*, logging_level, logging_format, log_dir, filename,
|
||||
max_bytes, backup_count):
|
||||
"""Configure the root logger that is used for Ray's python components.
|
||||
|
||||
For example, it should be used for monitor, dashboard, and log monitor.
|
||||
The only exception is workers. They use the different logging config.
|
||||
|
||||
Args:
|
||||
logging_level(str | int): Logging level in string or logging enum.
|
||||
logging_format(str): Logging format string.
|
||||
log_dir(str): Log directory path.
|
||||
filename(str): Name of the file to write logs.
|
||||
max_bytes(int): Same argument as RotatingFileHandler's maxBytes.
|
||||
backup_count(int): Same argument as RotatingFileHandler's backupCount.
|
||||
"""
|
||||
# Get the root logger.
|
||||
logger = logging.getLogger("")
|
||||
if type(logging_level) is str:
|
||||
logging_level = logging.getLevelName(logging_level.upper())
|
||||
assert filename, "filename argument should not be None."
|
||||
assert log_dir, "log_dir should not be None."
|
||||
handler = logging.handlers.RotatingFileHandler(
|
||||
os.path.join(log_dir, filename),
|
||||
maxBytes=max_bytes,
|
||||
backupCount=backup_count)
|
||||
logger.setLevel(logging_level)
|
||||
handler.setFormatter(logging.Formatter(logging_format))
|
||||
logger.addHandler(handler)
|
||||
|
||||
|
||||
"""
|
||||
All components underneath here is used specifically for the default_worker.py.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user