Skip to content

Commit 017917d

Browse files
committed
Trying to enhance log readability.
1 parent 992bf3c commit 017917d

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

build_docs.py

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

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

@@ -650,6 +652,7 @@ def full_build(self):
650652
def run(self) -> bool:
651653
"""Build and publish a Python doc, for a language, and a version."""
652654
start_time = perf_counter()
655+
logging.info("Running.")
653656
try:
654657
self.cpython_repo.switch(self.version.branch_or_tag)
655658
if self.language.tag != "en":
@@ -659,11 +662,7 @@ def run(self) -> bool:
659662
self.copy_build_to_webroot()
660663
self.save_state(build_duration=perf_counter() - start_time)
661664
except Exception as err:
662-
logging.exception(
663-
"Exception while building %s version %s",
664-
self.language.tag,
665-
self.version.name,
666-
)
665+
logging.exception("Badly handled exception, human, please help.")
667666
if sentry_sdk:
668667
sentry_sdk.capture_exception(err)
669668
return False
@@ -708,11 +707,7 @@ def translation_branch(self):
708707

709708
def build(self):
710709
"""Build this version/language doc."""
711-
logging.info(
712-
"Build start for version: %s, language: %s",
713-
self.version.name,
714-
self.language.tag,
715-
)
710+
logging.info("Build start.")
716711
sphinxopts = list(self.language.sphinxopts)
717712
sphinxopts.extend(["-q"])
718713
if self.language.tag != "en":
@@ -788,11 +783,7 @@ def build(self):
788783
setup_switchers(
789784
self.versions, self.languages, self.checkout / "Doc" / "build" / "html"
790785
)
791-
logging.info(
792-
"Build done for version: %s, language: %s",
793-
self.version.name,
794-
self.language.tag,
795-
)
786+
logging.info("Build done.")
796787

797788
def build_venv(self):
798789
"""Build a venv for the specific Python version.
@@ -813,11 +804,7 @@ def build_venv(self):
813804

814805
def copy_build_to_webroot(self):
815806
"""Copy a given build to the appropriate webroot with appropriate rights."""
816-
logging.info(
817-
"Publishing start for version: %s, language: %s",
818-
self.version.name,
819-
self.language.tag,
820-
)
807+
logging.info("Publishing start.")
821808
self.www_root.mkdir(parents=True, exist_ok=True)
822809
if self.language.tag == "en":
823810
target = self.www_root / self.version.name
@@ -887,7 +874,7 @@ def copy_build_to_webroot(self):
887874
]
888875
)
889876
if self.full_build:
890-
logging.debug("Copying dist files")
877+
logging.debug("Copying dist files.")
891878
run(
892879
[
893880
"chown",
@@ -930,11 +917,7 @@ def copy_build_to_webroot(self):
930917
purge(*prefixes)
931918
for prefix in prefixes:
932919
purge(*[prefix + p for p in changed])
933-
logging.info(
934-
"Publishing done for version: %s, language: %s",
935-
self.version.name,
936-
self.language.tag,
937-
)
920+
logging.info("Publishing done")
938921

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

0 commit comments

Comments
 (0)