[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:
SangBin Cho
2020-11-30 19:03:55 -08:00
committed by GitHub
parent 2708b3abbc
commit 8223a33bff
10 changed files with 162 additions and 56 deletions
+30
View File
@@ -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.
"""