Skip to content

Commit 04b1a7c

Browse files
committed
Trying to enhance log readability.
1 parent 547f6a1 commit 04b1a7c

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

build_docs.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ def run(cmd, cwd=None) -> subprocess.CompletedProcess:
249249
cmdstring,
250250
indent("\n".join(result.stdout.split("\n")[-20:]), " "),
251251
)
252-
else:
253-
logging.debug("Run: %r OK", cmdstring)
254252
result.check_returncode()
255253
return result
256254

@@ -610,11 +608,15 @@ def parse_args():
610608
def setup_logging(log_directory: Path):
611609
"""Setup logging to stderr if ran by a human, or to a file if ran from a cron."""
612610
if sys.stderr.isatty():
613-
logging.basicConfig(format="%(levelname)s:%(message)s", stream=sys.stderr)
611+
logging.basicConfig(
612+
format="%(asctime)s %(levelname)s: %(message)s", stream=sys.stderr
613+
)
614614
else:
615615
log_directory.mkdir(parents=True, exist_ok=True)
616616
handler = logging.handlers.WatchedFileHandler(log_directory / "docsbuild.log")
617-
handler.setFormatter(logging.Formatter("%(levelname)s:%(asctime)s:%(message)s"))
617+
handler.setFormatter(
618+
logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
619+
)
618620
logging.getLogger().addHandler(handler)
619621
logging.getLogger().setLevel(logging.DEBUG)
620622

@@ -651,6 +653,7 @@ def full_build(self):
651653
def run(self) -> bool:
652654
"""Build and publish a Python doc, for a language, and a version."""
653655
start_time = perf_counter()
656+
logging.info("Running.")
654657
try:
655658
self.cpython_repo.switch(self.version.branch_or_tag)
656659
if self.language.tag != "en":
@@ -660,11 +663,7 @@ def run(self) -> bool:
660663
self.copy_build_to_webroot()
661664
self.save_state(build_duration=perf_counter() - start_time)
662665
except Exception as err:
663-
logging.exception(
664-
"Exception while building %s version %s",
665-
self.language.tag,
666-
self.version.name,
667-
)
666+
logging.exception("Badly handled exception, human, please help.")
668667
if sentry_sdk:
669668
sentry_sdk.capture_exception(err)
670669
return False
@@ -709,11 +708,7 @@ def translation_branch(self):
709708

710709
def build(self):
711710
"""Build this version/language doc."""
712-
logging.info(
713-
"Build start for version: %s, language: %s",
714-
self.version.name,
715-
self.language.tag,
716-
)
711+
logging.info("Build start.")
717712
sphinxopts = list(self.language.sphinxopts)
718713
sphinxopts.extend(["-q"])
719714
if self.language.tag != "en":
@@ -789,11 +784,7 @@ def build(self):
789784
setup_switchers(
790785
self.versions, self.languages, self.checkout / "Doc" / "build" / "html"
791786
)
792-
logging.info(
793-
"Build done for version: %s, language: %s",
794-
self.version.name,
795-
self.language.tag,
796-
)
787+
logging.info("Build done.")
797788

798789
def build_venv(self):
799790
"""Build a venv for the specific Python version.
@@ -814,11 +805,7 @@ def build_venv(self):
814805

815806
def copy_build_to_webroot(self):
816807
"""Copy a given build to the appropriate webroot with appropriate rights."""
817-
logging.info(
818-
"Publishing start for version: %s, language: %s",
819-
self.version.name,
820-
self.language.tag,
821-
)
808+
logging.info("Publishing start.")
822809
self.www_root.mkdir(parents=True, exist_ok=True)
823810
if self.language.tag == "en":
824811
target = self.www_root / self.version.name
@@ -888,7 +875,7 @@ def copy_build_to_webroot(self):
888875
]
889876
)
890877
if self.full_build:
891-
logging.debug("Copying dist files")
878+
logging.debug("Copying dist files.")
892879
run(
893880
[
894881
"chown",
@@ -931,11 +918,7 @@ def copy_build_to_webroot(self):
931918
purge(*prefixes)
932919
for prefix in prefixes:
933920
purge(*[prefix + p for p in changed])
934-
logging.info(
935-
"Publishing done for version: %s, language: %s",
936-
self.version.name,
937-
self.language.tag,
938-
)
921+
logging.info("Publishing done")
939922

940923
def save_state(self, build_duration):
941924
"""Save current cpython sha1 and current translation sha1.
@@ -1104,6 +1087,11 @@ def build_docs(args) -> bool:
11041087
cpython_repo.update()
11051088
while todo:
11061089
version, language = todo.pop()
1090+
logging.root.handlers[0].setFormatter(
1091+
logging.Formatter(
1092+
f"%(asctime)s %(levelname)s {language.tag}/{version.name}: %(message)s"
1093+
)
1094+
)
11071095
if sentry_sdk:
11081096
with sentry_sdk.configure_scope() as scope:
11091097
scope.set_tag("version", version.name)
@@ -1112,6 +1100,10 @@ def build_docs(args) -> bool:
11121100
version, versions, language, languages, cpython_repo, **vars(args)
11131101
)
11141102
all_built_successfully &= builder.run()
1103+
logging.root.handlers[0].setFormatter(
1104+
logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
1105+
)
1106+
11151107
build_sitemap(versions, languages, args.www_root, args.group)
11161108
build_404(args.www_root, args.group)
11171109
build_robots_txt(

0 commit comments

Comments
 (0)