Changeset - a6accd29d038
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 11 years ago 2015-03-28 21:08:01
thomas.de.schampheleire@gmail.com
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.
1 file changed with 19 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -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.
 

	
0 comments (0 inline, 0 general)