Skip to content

Commit

Permalink
[Core] Pass logs through if sphinx-doctest is running (ray-project#36306
Browse files Browse the repository at this point in the history
)

---------

Signed-off-by: pdmurray <peynmurray@gmail.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
  • Loading branch information
peytondmurray authored and arvind-chandra committed Aug 31, 2023
1 parent 62d4ac8 commit c5f1c69
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ clean:
rm -rf ./source/rllib/package_ref/doc*

html:
SKIP_LOG_RESET=True $(SPHINXBUILD) -W --keep-going -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
$(SPHINXBUILD) -W --keep-going -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

develop:
SKIP_LOG_RESET=True FAST=True $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
FAST=True $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
@echo "View the documentation by opening a browser and going to $(BUILDDIR)/html/index.html."
Expand Down
4 changes: 4 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"sphinx_tabs.tabs",
"sphinx_remove_toctrees",
"sphinx_design",
"sphinx.ext.intersphinx",
]

# Prune deep toc-trees on demand for smaller html and faster builds.
Expand Down Expand Up @@ -107,6 +108,9 @@
"replacements",
]

intersphinx_mapping = {
"sklearn": ("https://scikit-learn.org/stable/", None),
}

# Cache notebook outputs in _build/.jupyter_cache
# To prevent notebook execution, set this to "off". To force re-execution, set this to "force".
Expand Down
6 changes: 1 addition & 5 deletions python/ray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import os
import sys

# For cases like docs builds, we want the default logging config.
skip_reset = os.environ.get("SKIP_LOG_RESET", False)
if not skip_reset:
log.generate_logging_config()

log.generate_logging_config()
logger = logging.getLogger(__name__)


Expand Down
25 changes: 25 additions & 0 deletions python/ray/_private/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
import re
from logging.config import dictConfig
import threading
from typing import Union


def _print_loggers():
"""Print a formatted list of loggers and their handlers for debugging."""
loggers = {logging.root.name: logging.root}
loggers.update(dict(sorted(logging.root.manager.loggerDict.items())))
for name, logger in loggers.items():
if isinstance(logger, logging.Logger):
print(f" {name}: disabled={logger.disabled}, propagate={logger.propagate}")
for handler in logger.handlers:
print(f" {handler}")


def clear_logger(logger: Union[str, logging.Logger]):
"""Reset a logger, clearing its handlers and enabling propagation.
Args:
logger: Logger to be cleared
"""
if isinstance(logger, str):
logger = logging.getLogger(logger)
logger.propagate = True
logger.handlers.clear()


class ContextFilter(logging.Filter):
Expand Down Expand Up @@ -134,5 +158,6 @@ def generate_logging_config():
"filters": filters,
"handlers": handlers,
"loggers": loggers,
"disable_existing_loggers": False,
}
)
4 changes: 1 addition & 3 deletions python/ray/_private/ray_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def setup_component_logger(
Returns:
the created or modified logger.
"""
ray_logger = logging.getLogger("ray")
ray_logger.propagate = True
ray_logger.handlers.clear()
ray._private.log.clear_logger("ray")

logger = logging.getLogger(logger_name)
if type(logging_level) is str:
Expand Down
9 changes: 9 additions & 0 deletions python/ray/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,15 @@ def test_log_level_settings(
assert len(caplog.records) == 0, "Log message found where none are expected."


def test_log_with_import():

logger = logging.getLogger(__name__)
assert not logger.disabled
ray.log.logger_initialized = False
ray.log.generate_logging_config()
assert not logger.disabled


if __name__ == "__main__":
import sys

Expand Down

0 comments on commit c5f1c69

Please sign in to comment.