From 506cf91716ff32c3747829b8556ce2d26b1936a4 Mon Sep 17 00:00:00 2001 From: Paul Barker Date: Mon, 7 Jun 2021 11:02:52 +0100 Subject: 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 Signed-off-by: Konstantin Ryabitsev Link: https://lore.kernel.org/r/20210607100252.8253-3-paul@pbarker.dev --- b4/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3