def QueryLogs(args: 'argparse.Namespace') -> None:
  """Query GCP logs.

  Args:
    args (argparse.Namespace): Arguments from ArgumentParser.

  Raises:
    ValueError: If the start or end date is not properly formatted.
    AttributeError: If no project_id was provided and none was inferred
        from the gcloud environment.
  """

  AssignProjectID(args)

  logs = gcp_log.GoogleCloudLog(args.project.split(','))

  try:
    if args.start:
      datetime.strptime(args.start, '%Y-%m-%dT%H:%M:%SZ')
    if args.end:
      datetime.strptime(args.end, '%Y-%m-%dT%H:%M:%SZ')
  except ValueError as error:
    sys.exit(str(error))

  qfilter = ''

  if args.start:
    qfilter += 'timestamp>="{0:s}" '.format(args.start)
  if args.start and args.end:
    qfilter += 'AND '
  if args.end:
    qfilter += 'timestamp<="{0:s}" '.format(args.end)

  if args.filter and (args.start or args.end):
    qfilter += 'AND '
    qfilter += args.filter
  elif args.filter:
    qfilter += args.filter

  results = logs.ExecuteQuery(qfilter.split(',') if qfilter else None)
  logger.info('Found {0:d} log entries:'.format(len(results)))
  for line in results:
    print(json.dumps(line))
Query GCP logs.

Args:
args (argparse.Namespace): Arguments from ArgumentParser.

Raises:
ValueError: If the start or end date is not properly formatted.
AttributeError: If no project_id was provided and none was inferred
from the gcloud environment.
tools/gcp_cli.py