Beispiel #1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The list of log entries.
    """
        printer = logs_util.LogPrinter()
        printer.RegisterFormatter(logs_util.FormatRequestLogEntry)
        printer.RegisterFormatter(logs_util.FormatNginxLogEntry)
        printer.RegisterFormatter(logs_util.FormatAppEntry)
        project = properties.VALUES.core.project.Get(required=True)
        filters = logs_util.GetFilters(project, args.logs, args.service,
                                       args.version, args.level)

        lines = []
        # pylint: disable=g-builtin-op, For the .keys() method
        for entry in common.FetchLogs(log_filter=' AND '.join(filters),
                                      order_by='DESC',
                                      limit=args.limit):
            lines.append(printer.Format(entry))
        for line in reversed(lines):
            log.out.Print(line)
Beispiel #2
0
    def Run(self, args):
        printer = logs_util.LogPrinter()
        printer.RegisterFormatter(logs_util.FormatRequestLogEntry)
        printer.RegisterFormatter(logs_util.FormatAppEntry)
        project = properties.VALUES.core.project.Get(required=True)
        filters = logs_util.GetFilters(project, args.logs, args.service,
                                       args.version, args.level)

        log_fetcher = stream.LogFetcher(filters=filters, polling_interval=1)
        for log_entry in log_fetcher.YieldLogs():
            log.out.Print(printer.Format(log_entry))