# HG changeset patch # User Thomas De Schampheleire # Date 2015-03-28 21:08:01 # 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 --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -406,6 +406,25 @@ class _Message(object): 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.