diff sat/plugins/plugin_comp_ap_gateway/__init__.py @ 3881:2e4a0f6050bd

component AP gateway: better verbose logging: gather data to show according to verbosity and log it all at once with a small `<<<` or `>>>` indicating the direction. With a verbosity of 3, headers are also shown.
author Goffi <goffi@goffi.org>
date Wed, 31 Aug 2022 17:07:03 +0200
parents 03761f8ba8bb
children 6da749bbf320
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_ap_gateway/__init__.py	Wed Aug 31 17:07:01 2022 +0200
+++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py	Wed Aug 31 17:07:03 2022 +0200
@@ -1166,9 +1166,10 @@
         if self.verbose:
             __, actor_args = self.parseAPURL(actor_id)
             actor_account = actor_args[0]
-            log.info(
-                f"==> {actor_account} is signing and posting to {url}:\n{pformat(doc)}"
-            )
+            to_log = [
+                "",
+                f">>> {actor_account} is signing and posting to {url}:\n{pformat(doc)}"
+            ]
 
         p_url = parse.urlparse(url)
         body = json.dumps(doc).encode()
@@ -1183,9 +1184,13 @@
         }
         headers, __ = self.getSignatureData(self.getKeyId(actor_id), headers)
 
-        headers["Content-Type"] = (
-            'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
-        )
+        if self.verbose:
+            if self.verbose>=3:
+                h_to_log = "\n".join(f"    {k}: {v}" for k,v in headers.items())
+                to_log.append(f"  headers:\n{h_to_log}")
+            to_log.append("---")
+            log.info("\n".join(to_log))
+
         resp = await treq.post(
             url,
             body,