Esempio n. 1
0
 def _extract_info(self):
     """Dissect the 'message' contents to extract event name and any
     embedded key-value pairs.
     """
     rec = self.record  # alias
     message = rec.get('message', rec.get('msg', None))
     if message is None:
         g_log.error(
             "No 'message' or 'msg' field found in record: {}".format(rec))
         message = "unknown;Message field not found"
     # Split out event name
     try:
         event, msg = message.split(log_common.EVENT_MSG_SEP, 1)
     except ValueError:
         event, msg = 'event', message  # assign generic event name
         if self.strict:
             raise ValueError(
                 "Cannot split event/msg in '{}'".format(message))
     # Break into key=value pairs
     text = parse_kvp(msg, rec)
     # Anything not parsed goes back into message
     rec['msg'] = text
     # Event gets its own field, too
     rec['event'] = event
     # Levelname is too long
     if 'levelname' in rec:
         rec['level'] = rec['levelname']
         del rec['levelname']
     else:
         rec['level'] = logging.getLevelName(logging.INFO)
Esempio n. 2
0
 def _extract_info(self):
     """Dissect the 'message' contents to extract event name and any
     embedded key-value pairs.
     """
     rec = self.record  # alias
     message = rec.get('message', rec.get('msg', None))
     if message is None:
         g_log.error("No 'message' or 'msg' field found in record: {}"
                     .format(rec))
         message = "unknown;Message field not found"
     # Split out event name
     try:
         event, msg = message.split(log_common.EVENT_MSG_SEP, 1)
     except ValueError:
         event, msg = 'event', message  # assign generic event name
         if self.strict:
             raise ValueError("Cannot split event/msg in '{}'"
                              .format(message))
     # Break into key=value pairs
     text = parse_kvp(msg, rec)
     # Anything not parsed goes back into message
     rec['msg'] = text
     # Event gets its own field, too
     rec['event'] = event
     # Levelname is too long
     if 'levelname' in rec:
         rec['level'] = rec['levelname']
         del rec['levelname']
     else:
         rec['level'] = logging.getLevelName(logging.INFO)