From 66c1e16c91bdf9c9219c13f9b465a11a43e35df1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 26 Jun 2023 21:26:56 +0200 Subject: [PATCH] Continued: - fixed error messages, missed adding the actual variables being logged - logged count of updated fields - log header (mostly bs4.element.Tag) --- fba/commands.py | 4 ++-- fba/http/federation.py | 11 ++++++----- fba/models/instances.py | 4 ++-- fba/networks/lemmy.py | 4 ++-- fba/networks/mastodon.py | 4 ++-- fba/networks/pleroma.py | 1 + fba/utils.py | 8 ++++---- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index ed180bc..9334cfb 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -161,7 +161,7 @@ def fetch_bkali(args: argparse.Namespace) -> int: logger.warning("entry()=%d does not contain 'domain' - SKIPPED!", len(entry)) continue elif not utils.is_domain_wanted(entry["domain"]): - logger.debug("entry[domain]='%s' is not wanted - SKIPPED!") + logger.debug("entry[domain]='%s' is not wanted - SKIPPED!", entry["domain"]) continue elif instances.is_registered(entry["domain"]): logger.debug("entry[domain]='%s' is already registered - SKIPPED!", entry["domain"]) @@ -404,7 +404,7 @@ def fetch_observer(args: argparse.Namespace) -> int: for software in types: logger.debug("software='%s' - BEFORE!", software) if args.software is not None and args.software != software: - logger.debug("args.software='%s' does not match software='%s' - SKIPPED!") + logger.debug("args.software='%s' does not match software='%s' - SKIPPED!", args.software, software) continue doc = None diff --git a/fba/http/federation.py b/fba/http/federation.py index e203c16..630b87b 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -191,7 +191,7 @@ def fetch_peers(domain: str, software: str, origin: str) -> list: logger.debug("Querying API path='%s' was successful: domain='%s',data[json][%s]()=%d", path, domain, type(data['json']), len(data['json'])) peers = data["json"] - logger.debug("Marking domain='%s' as successfully handled ...") + logger.debug("Marking domain='%s' as successfully handled ...", domain) instances.set_success(domain) break @@ -308,7 +308,7 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: if "error_message" not in data: nodeinfo = data["json"] - logger.debug("Marking domain='%s' as successfully handled ...") + logger.debug("Marking domain='%s' as successfully handled ...", domain) instances.set_success(domain) logger.debug("Found entries: nodeinfo()=%d,domain='%s'", len(nodeinfo), domain) @@ -345,10 +345,11 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: instances.set_detection_mode(domain, "AUTO_DISCOVERY") instances.set_nodeinfo_url(domain, link["href"]) - logger.debug("Marking domain='%s' as successfully handled ...") + logger.debug("Marking domain='%s' as successfully handled ...", domain) instances.set_success(domain) break else: + logger.debug("Setting last error for domain='%s',data[]='%s'", domain, type(data)) instances.set_last_error(domain, data) else: logger.warning("Unknown 'rel' value: domain='%s',link[rel]='%s'", domain, link["rel"]) @@ -553,7 +554,7 @@ def add_peers(rows: dict) -> list: logger.debug("peer is empty - SKIPPED") continue elif isinstance(peer, dict) and "domain" in peer: - logger.debug("peer[domain]='%s'", peer['domain']) + logger.debug("peer[domain]='%s'", peer["domain"]) peer = tidyup.domain(peer["domain"]) elif isinstance(peer, str): logger.debug("peer='%s'", peer) @@ -566,7 +567,7 @@ def add_peers(rows: dict) -> list: logger.debug("peer='%s' is not wanted - SKIPPED!", peer) continue - logger.debug("Adding peer='%s' ...", peer) + logger.debug("Appending peer='%s' ...", peer) peers.append(peer) logger.debug("peers()=%d - EXIT!", len(peers)) diff --git a/fba/models/instances.py b/fba/models/instances.py index d255506..a812a85 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -126,7 +126,7 @@ def update_data(domain: str): logger.debug("sql_string='%s',fields()=%d", sql_string, len(fields)) sql_string = "UPDATE instances SET" + sql_string + " last_updated = ? WHERE domain = ? LIMIT 1" - logger.debug("Executing SQL: '%s'", sql_string) + logger.debug("Executing SQL: sql_string='%s',fields()=%d", sql_string, len(fields)) database.cursor.execute(sql_string, fields) logger.debug("rowcount=%d", database.cursor.rowcount) @@ -376,7 +376,7 @@ def set_total_peers(domain: str, peers: list): domain_helper.raise_on(domain) if not isinstance(peers, list): - raise ValueError(f"Parameter peers[]='{type(peers)}' is not 'list': '%s'") + raise ValueError(f"Parameter peers[]='{type(peers)}' is not 'list'") # Set timestamp _set_data("total_peers", domain, len(peers)) diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index 47afc1b..946d0eb 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -68,7 +68,7 @@ def fetch_peers(domain: str, origin: str) -> list: logger.debug("Found federated_instances for domain='%s'", domain) peers = peers + federation.add_peers(data["json"]["federated_instances"]) - logger.debug("Marking domain='%s' as successfully handled ...") + logger.debug("Marking domain='%s' as successfully handled ...", domain) instances.set_success(domain) if len(peers) == 0: @@ -242,7 +242,7 @@ def fetch_instances(domain: str, origin: str) -> list: logger.debug("Appending peer='%s' ...", peer) peers.append(peer) - logger.debug("Marking domain='%s' as successfully handled ...") + logger.debug("Marking domain='%s' as successfully handled ...", domain) instances.set_success(domain) except network.exceptions as exception: diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index fcfbc6e..ca33c10 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -172,7 +172,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: # Getting blocklist rows = data["json"] - logger.debug("Marking domain='%s' as successfully handled ...") + logger.debug("Marking domain='%s' as successfully handled ...", domain) instances.set_success(domain) if len(rows) == 0: @@ -199,7 +199,7 @@ def fetch_blocks(domain: str, nodeinfo_url: str) -> list: "block_level": block["severity"] }) else: - logger.debug("domain='%s' has no block list") + logger.debug("domain='%s' has no block list", domain) except network.exceptions as exception: logger.warning("domain='%s',exception[%s]='%s'", domain, type(exception), str(exception)) diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 34c1a51..64729f1 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -366,6 +366,7 @@ def fetch_blocks_from_about(domain: str) -> dict: return list() for header in doc.find_all("h2"): + logger.debug("header[%s]='%s'", type(header), header) header_text = tidyup.reason(header.text) logger.debug("header_text='%s' - BEFORE!", header_text) diff --git a/fba/utils.py b/fba/utils.py index bbbf3b4..441932f 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -81,7 +81,7 @@ def process_domain(domain: str, blocker: str, command: str) -> bool: elif command == "": raise ValueError("Parameter 'command' is empty") - logger.debug("domain='%s' - BEFORE!") + logger.debug("domain='%s' - BEFORE!", domain) domain = deobfuscate_domain(domain, blocker) logger.debug("domain='%s' - DEOBFUSCATED!", domain) @@ -105,9 +105,9 @@ def process_domain(domain: str, blocker: str, command: str) -> bool: logger.warning("Exception '%s' during fetching instances (%s) from domain='%s'", type(exception), command, domain) instances.set_last_error(domain, exception) - logger.debug("Checking if domain='%s' has pending updates ...") + logger.debug("Checking if domain='%s' has pending updates ...", domain) if instances.has_pending(domain): - logger.debug("Flushing updates for domain='%s' ...") + logger.debug("Flushing updates for domain='%s' ...", domain) instances.update_data(domain) logger.debug("processed='%s' - EXIT!", processed) @@ -134,7 +134,7 @@ def find_domains(tags: bs4.element.ResultSet, search: str) -> list: domain = tidyup.domain(tag.find("em").contents[0]) if not is_domain_wanted(domain): - logger.debug("domain='%s' is not wanted - SKIPPED!") + logger.debug("domain='%s' is not wanted - SKIPPED!", domain) continue logger.debug("Appending domain='%s'", domain) -- 2.39.5