Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,18 +567,19 @@ def parse_args():
return args


def setup_logging(log_directory: Path):
def setup_logging(log_directory: Path, select_output: str | None):
"""Setup logging to stderr if run by a human, or to a file if run from a cron."""
log_format = "%(asctime)s %(levelname)s: %(message)s"
if sys.stderr.isatty():
logging.basicConfig(
format="%(asctime)s %(levelname)s: %(message)s", stream=sys.stderr
)
logging.basicConfig(format=log_format, stream=sys.stderr)
else:
log_directory.mkdir(parents=True, exist_ok=True)
handler = logging.handlers.WatchedFileHandler(log_directory / "docsbuild.log")
handler.setFormatter(
logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
)
if select_output is None:
filename = log_directory / "docsbuild.log"
else:
filename = log_directory / f"docsbuild-{select_output}.log"
handler = logging.handlers.WatchedFileHandler(filename)
handler.setFormatter(logging.Formatter(log_format))
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.DEBUG)

Expand Down Expand Up @@ -1206,7 +1207,7 @@ def _checkout_name(select_output: str | None) -> str:
def main():
"""Script entry point."""
args = parse_args()
setup_logging(args.log_directory)
setup_logging(args.log_directory, args.select_output)

if args.select_output is None:
build_docs_with_lock(args, "build_docs.lock")
Expand Down