Example #1
0
  def emit(self, record):
    """Emit a record.

    This implementation is based on the implementation of
    StreamHandler.emit()."""
    try:
      message = self._AppLogsMessage(record)
      if isinstance(message, unicode):
        message = message.encode("UTF-8")

      if auth.is_current_user_admin():
        title = u'%s [%s:%s] inside \'%s()\'' % (record.levelname, 
          record.filename, record.lineno, record.funcName)

        try:
          sess = auth.get_session()
          current_log_records = sess.get(u'log_records', None)
          if not isinstance(current_log_records, list):
            sess[u'log_records'] = []
          if title:
            sess[u'log_records'].append({u'title': title, u'payload': message})
        except (AttributeError, KeyError), e:
          raise
    except (KeyboardInterrupt, SystemExit):
      raise
    except:
      self.handleError(record)
 def session(self):
   return auth.get_session()