示例#1
0
    def Log(self, format_str, *args):
        """Logs the message using the flow's standard logging.

    Args:
      format_str: Format string
      *args: arguments to the format string
    Raises:
      RuntimeError: on parent missing logs_collection
    """
        format_str = utils.SmartUnicode(format_str)

        try:
            # The status message is always in unicode
            status = format_str % args
        except TypeError:
            logging.error(
                "Tried to log a format string with the wrong number "
                "of arguments: %s", format_str)
            status = format_str

        logging.info("%s: %s", self.session_id, status)

        self.SetStatus(utils.SmartUnicode(status))

        logs_collection = self.OpenLogsCollection(
            self.args.logs_collection_urn)
        logs_collection.Add(
            rdfvalue.FlowLog(client_id=None,
                             urn=self.session_id,
                             flow_name=self.flow_obj.__class__.__name__,
                             log_message=status))
        logs_collection.Flush()
示例#2
0
 def CreateCollectionWithMessages(self, messages):
     with self.ACLChecksDisabled():
         with aff4.FACTORY.Create("aff4:/tmp/collection",
                                  aff4_type="RDFValueCollection",
                                  mode="w",
                                  token=self.token) as fd:
             for message in messages:
                 fd.Add(rdfvalue.FlowLog(log_message=message))