Skip to content

Commit a884721

Browse files
committed
Set the logging filename based upon --select-output
1 parent 5d26f06 commit a884721

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

build_docs.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,19 @@ def parse_args():
567567
return args
568568

569569

570-
def setup_logging(log_directory: Path):
570+
def setup_logging(log_directory: Path, select_output: str | None):
571571
"""Setup logging to stderr if run by a human, or to a file if run from a cron."""
572+
log_format = "%(asctime)s %(levelname)s: %(message)s"
572573
if sys.stderr.isatty():
573-
logging.basicConfig(
574-
format="%(asctime)s %(levelname)s: %(message)s", stream=sys.stderr
575-
)
574+
logging.basicConfig(format=log_format, stream=sys.stderr)
576575
else:
577576
log_directory.mkdir(parents=True, exist_ok=True)
578-
handler = logging.handlers.WatchedFileHandler(log_directory / "docsbuild.log")
579-
handler.setFormatter(
580-
logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
581-
)
577+
if select_output is None:
578+
filename = log_directory / "docsbuild.log"
579+
else:
580+
filename = log_directory / f"docsbuild-{select_output}.log"
581+
handler = logging.handlers.WatchedFileHandler(filename)
582+
handler.setFormatter(logging.Formatter(log_format))
582583
logging.getLogger().addHandler(handler)
583584
logging.getLogger().setLevel(logging.DEBUG)
584585

@@ -1206,7 +1207,7 @@ def _checkout_name(select_output: str | None) -> str:
12061207
def main():
12071208
"""Script entry point."""
12081209
args = parse_args()
1209-
setup_logging(args.log_directory)
1210+
setup_logging(args.log_directory, args.select_output)
12101211

12111212
if args.select_output is None:
12121213
build_docs_with_lock(args, "build_docs.lock")

0 commit comments

Comments
 (0)