aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Barker <paul@pbarker.dev>2021-06-07 11:02:52 +0100
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-06-07 08:49:23 -0400
commit506cf91716ff32c3747829b8556ce2d26b1936a4 (patch)
treee92684d32d1454771ed322a588ce01cfca0abd2e
parent366bcd1fd8a10b6125e591f0c35cc85b10c9c950 (diff)
downloadb4-506cf91716ff32c3747829b8556ce2d26b1936a4.tar.gz
Include dkim log output when -d/--debug argument is passed
We can pass a logger object to dkim.verify() which will be used to report internal errors and debugging info. This can be helpful when investigating DKIM verification issues but is probably not wanted during normal operation so the log level of each message is reset to DEBUG. Each message is also prefixed with 'DKIM: ' to identify its origin when debug output is enabled. Signed-off-by: Paul Barker <paul@pbarker.dev> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org> Link: https://lore.kernel.org/r/20210607100252.8253-3-paul@pbarker.dev
-rw-r--r--b4/__init__.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index 168b722..9721e22 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -47,6 +47,17 @@ __VERSION__ = '0.8-dev'
logger = logging.getLogger('b4')
+def _dkim_log_filter(record):
+ # Hide all dkim logging output in normal operation by setting the level to
+ # DEBUG. If debugging output has been enabled then prefix dkim logging
+ # output to make its origin clear.
+ record.levelno = logging.DEBUG
+ record.levelname = 'DEBUG'
+ record.msg = 'DKIM: ' + record.msg
+ return True
+dkimlogger = logger.getChild('dkim')
+dkimlogger.addFilter(_dkim_log_filter)
+
HUNK_RE = re.compile(r'^@@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? @@')
FILENAME_RE = re.compile(r'^(---|\+\+\+) (\S+)')
@@ -1028,7 +1039,7 @@ class LoreMessage:
signtime = self.date
self.msg._headers.append((hn, hval)) # noqa
- res = dkim.verify(self.msg.as_bytes())
+ res = dkim.verify(self.msg.as_bytes(), logger=dkimlogger)
attestor = LoreAttestorDKIM(res, identity, signtime, errors)
logger.debug('DKIM verify results: %s=%s', identity, res)