From 0a69e3fabc47b26fc8cd73bb37c210d48145a24f Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Thu, 18 Jul 2024 00:08:19 +0300 Subject: [PATCH] All log messages as JSON --- generator.py | 8 +++++--- jinja_helper.py | 6 +++++- sites.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/generator.py b/generator.py index c7ded40..1838c74 100644 --- a/generator.py +++ b/generator.py @@ -24,7 +24,7 @@ def setupDist(): try: shutil.rmtree(dist) except Exception as e: - print(e) + log(target="ERROR", message=f"removing {dist} failed", error=e) os.mkdir(dist) os.mkdir(top_sites) @@ -180,8 +180,10 @@ def genStaticFiles(results: dict): domains_dict = sites.getTop500() if len(domains_dict) > 0: - print("Got domain lists, counts:") - print("Total -", len(domains_dict)) + log( + target="INFO", + message="Got domain lists; total count {len(domains_dict)}", + ) else: raise Exception("No domains") diff --git a/jinja_helper.py b/jinja_helper.py index 09e5894..f461850 100644 --- a/jinja_helper.py +++ b/jinja_helper.py @@ -7,6 +7,8 @@ import json import subresource_integrity as integrity +from json_logger import log + def colourFromLetter(letter: str = "") -> str: if not letter: @@ -94,7 +96,9 @@ def renderTemplate( params.update({"title": params["dest_domain"]}) else: description = "" - print(f"Skipping canonical and description for: {filename}") + log( + target="INFO", message=f"Skipping canonical and description for: {filename}" + ) params.update({"description": description}) params.update({"canonical": canonical}) diff --git a/sites.py b/sites.py index 18fab25..9bdf782 100644 --- a/sites.py +++ b/sites.py @@ -19,7 +19,7 @@ def __init__(self): self.top500 = {} def __str__(self) -> str: - return f"{self.getTop500()}" + return f"{json.dumps(self.getTop500())}" def getTop500(self) -> dict: if self.cacheAge() > Sites.CACHE_MAX_AGE: