
    [                     n   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(                  ej*                  j,                  ej*                  j.                  ej*                  j0                         G d dej2                                      Zy)zCommand to read logs for a job.    )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 jobs.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.
          a&            To read log entries from for a Cloud Run job, run:

            $ {command} my-job

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

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

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

            $ {command} my-job --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 --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jobzName for a Cloud Run job.)help)add_argumentread_logs_libLogFilterArgsLoggingReadArgs)parsers    !lib/surface/run/jobs/logs/read.pyArgsz	Read.ArgsC   s2    
$?@'!!&)    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_jobzresource.labels.job_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.RunI   s    #'#3#3L#AtrGNN*_<=NN5@ANN5??456 7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      s1    
 &-< * *
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   UniverseCompatibleReleaseTracksReleaseTrackALPHABETAGACommandr   r;   r   r   <module>rJ      s    & &  % ' 1 > ( A 0 # T..33T5F5F5I5I=4<< = =r   