'Application-level logging of user actions.'

def log_action(self, user=None, action=None, context=None, params=None):

    if self.app.config.log_actions:
        action = self.app.model.UserAction(action=action, context=context, params=text_type(dumps(params)))
        try:
            if user:
                action.user = user
            else:
                action.user = self.user
        except:
            action.user = None
        try:
            action.session_id = self.galaxy_session.id
        except:
            action.session_id = None
        self.sa_session.add(action)
        self.sa_session.flush()
