Mercurial > kallithea
changeset 5185:a6accd29d038
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.
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> |
---|---|
date | Sat, 28 Mar 2015 21:08:01 +0100 |
parents | d91c4f0a470b |
children | 5fb4e6f884ce |
files | kallithea/lib/helpers.py |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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.