@@ -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)
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> --- b4/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)