
                         &   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d	lmZ dd
lmZ ddlmZ  ej&                  ej(                  j*                  ej(                  j,                         G d dej.                               Zy)z)Command to read logs for a job execution.    )absolute_import)division)print_function)unicode_literals)common)	FormatLog)base)read)flags)logc                   0    e Zd ZdZdddZed        Zd Zy)Readz'Read logs for Cloud Run job executions.a            {command} reads log entries. Log entries matching *--log-filter* are
          returned according to the specified --order.
          If the log entries come from multiple logs, then entries from
          different logs might be intermingled in the results.
          aX            To read log entries from for a Cloud Run job execution, run:

            $ {command} my-job-execution

          To read log entries with severity ERROR or higher, run:

            $ {command} my-job-execution --log-filter="severity>=ERROR"

          To read log entries written in a specific time window, run:

            $ {command} my-job-execution --log-filter='timestamp<="2015-05-31T23:59:59Z" AND timestamp>="2015-05-31T00:00:00Z"'

          To read up to 10 log entries in your job payloads that include the
          word `SearchText` and format the output in `JSON` format, run:

            $ {command} my-job-execution --log-filter="textPayload:SearchText" --limit=10 --format=json

          Detailed information about filters can be found at:
          [](https://cloud.google.com/logging/docs/view/advanced_filters)
          )DESCRIPTIONEXAMPLESc                 ~    | j                  dd       t        j                  |        t        j                  |        y )N	executionz#Name for a Cloud Run job execution.)help)add_argumentread_logs_libLogFilterArgsLoggingReadArgs)parsers    ,lib/surface/run/jobs/executions/logs/read.pyArgsz	Read.Args@   s2    
*OP'!!&)    c                 x   |j                  d      r|j                  gng }|j                  ddz         |j                  d|j                  z         |j                  dt	        j
                  |d      z         |j                  d       |t        j                  |      z  }g }t        j                  t        j                  |      |j                  |j                  	      }|D ]!  }t        |      }|s|j                  |       # t        |      D ]!  }t        j                   j#                  |       # y )
N
log_filterzresource.type = %s 
cloud_run_jobz1labels."run.googleapis.com/execution_name" = %s 
zresource.labels.location = %s 
T)promptzseverity >= DEFAULT 
)order_bylimit)IsSpecifiedr   appendr   r   	GetRegionr   MakeTimestampFiltersr   	FetchLogsJoinFiltersorderr!   r   reversedr   outPrint)selfargsfilterslineslogslog_line
output_loglines           r   RunzRead.RunF   s   #'#3#3L#AtrGNN*_<=NN<
..	 NN*U__T$-OO NN+,}11$77GE!!'*jjD X&j	Z  
 	ggmmD  r   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r4    r   r   r   r      s/    /-< * *
r   r   N)r8   
__future__r   r   r   r   googlecloudsdk.api_lib.loggingr   (googlecloudsdk.api_lib.logging.formatterr   googlecloudsdk.callioper	   googlecloudsdk.command_lib.logsr
   r   googlecloudsdk.command_lib.runr   googlecloudsdk.corer   ReleaseTracksReleaseTrackALPHABETACommandr   r;   r   r   <module>rH      sr    0 &  % ' 1 > ( A 0 # D%%++T->->-C-CDB4<< B EBr   