
    p                     t    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ d	 Z	 	 	 	 	 ddZy
)z0A library that contains common logging commands.    )absolute_import)division)unicode_literals)
list_pager)util)
exceptions)
propertiesc                     t        dD cg c]  }|j                  |       c}      st        j                  | d|z        y c c}w )N)z	projects/zorganizations/zfolders/zbillingAccounts/zrInvalid resource %s. Resource must be in the form [projects|folders|organizations|billingAccounts]/{{resource_id}})any
startswithr   InvalidArgumentException)argresource_namets      ,lib/googlecloudsdk/api_lib/logging/common.py_AssertValidResourcer      s`    	NN! q!N 
 
-
- K 	
 s   ANc                    |xs g }|D ]  }t        d|        |rt        d|       |j                  |       nH|sF|j                  dt        j                  j                  j
                  j                  d      z         t        |xs dd      }|j                         dk(  rd}nd	}t        j                         }|j                  j                  || |
      }t        j                  |j                  |d||d      S )a  Fetches log entries.

  This method uses Cloud Logging V2 api.
  https://cloud.google.com/logging/docs/api/introduction_v2

  Entries are sorted on the timestamp field, and afterwards filter is applied.
  If limit is passed, returns only up to that many matching entries.

  If neither log_filter nor log_ids are passed, no filtering is done.

  FetchLogs will query the combined resource set from "parent" and
  "resource_names".

  Args:
    log_filter: filter expression used in the request.
    order_by: the sort order, either DESC or ASC.
    limit: how many entries to return.
    parent: the name of the log's parent resource, e.g. "projects/foo" or
      "organizations/123" or "folders/123". Defaults to the current project if
      no `resource_names` are provided.
    resource_names: if present, resource names to query.

  Returns:
    A generator that returns matching log entries.
    Callers are responsible for handling any http exceptions.
  resource_namesparentzprojects/%sT)requiredi  DESCztimestamp descztimestamp asc)resourceNamesfilterorderByentriespageSize)fieldlimit
batch_sizebatch_size_attribute)r   appendr	   VALUEScoreprojectGetminupperr   	GetClientMESSAGES_MODULEListLogEntriesRequestr   YieldFromListr   )	
log_filterorder_byr   r   r   name	page_sizeclientrequests	            r   	FetchLogsr2   (   s    > "'R.d)40  6*&!-$++0088<<d<KL M
 %-4&)^^HH>>&""88":x 9 I'		!	!nngYe
= =    )Nr   NNN)__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   googlecloudsdk.corer	   r   r2    r3   r   <module>r;      s:     7 &  ' ' / . * !	7=r3   