# HG changeset patch # User Thomas De Schampheleire # Date 1427573281 -3600 # Node ID a6accd29d038e694de0dfdc2316dd1b1bb72a06d # Parent d91c4f0a470ba0966d5d889f73ecc5851063961a helpers: add automatic logging of Flash messages shown to users Log all messages displayed through a flash to the user. Subsequent patches can change the log level for individual flash calls to make the log more useful. diff -r d91c4f0a470b -r a6accd29d038 kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Wed May 27 17:18:33 2015 +0200 +++ b/kallithea/lib/helpers.py Sat Mar 28 21:08:01 2015 +0100 @@ -406,6 +406,25 @@ class Flash(_Flash): + def __call__(self, message, category=None, ignore_duplicate=False, logf=None): + """ + Show a message to the user _and_ log it through the specified function + + category: notice (default), warning, error, success + logf: a custom log function - such as log.debug + + logf defaults to log.info, unless category equals 'success', in which + case logf defaults to log.debug. + """ + if logf is None: + logf = log.info + if category == 'success': + logf = log.debug + + logf('Flash %s: %s', category, message) + + super(Flash, self).__call__(message, category, ignore_duplicate) + def pop_messages(self): """Return all accumulated messages and delete them from the session.