
    a                     j   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 e
j                   e
j                  e
j                   j"                  e
j                   j$                  e
j                   j&                         G d
 de
j(                                      Zddde_        y)z'logging read' command.    )absolute_import)division)unicode_literals)common)util)arg_parsers)base)readc                   ,    e Zd ZdZed        Zd Zd Zy)ReadzRead log entries.c                    t        j                  |        t        j                  |        | j                         }|j	                  dt        j                         dd       |j                  d      }|j	                  ddd	d
       |j	                  ddd       |j	                  ddd       t        j                  | d       y)z Register flags for this command.z--resource-namesRESOURCEa!  Resource name(s) to read logs from. A resource can either be an top-level resource (e.g., "projects/my-project") or a full log view resource path (e.g., "projects/my-project/locations/my-location/buckets/my-bucket/views/my-view"). Multiple resources can be specified, separated by a comma.)typemetavarhelpzUThese arguments are used in conjunction with the parent to construct a view resource.)r   z
--locationTLOCATIONzmLocation of the log bucket. If this argument is provided then `--bucket` and `--view` must also be specified.)requiredr   r   z--bucketziId of the log bucket. If this argument is provided then `--location` and `--view` must also be specified.)r   r   z--viewzeId of the view. If this argument is provided then `--location` and `--bucket` must also be specified.zlog entries to readN)
read_logs_libLogFilterPositionalArgsLoggingReadArgsadd_mutually_exclusive_groupadd_argumentr   ArgListadd_argument_groupr   AddParentArgs)parsertarget_group
view_groups      lib/surface/logging/read.pyArgsz	Read.Args#   s     ))&1!!&)668L  "	  	 00% 1 &J :	  ; <  =
 >  ?
 	v45    c           	      d   t        j                  |      }||j                  r|j                  gng z  }|j                  d      rst	        j
                  t	        j
                  t	        j
                  t	        j                  |      d|j                        d|j                        d|j                        }n)|j                  d      rd }nt	        j                  |      }t        j                  t        j                  |d      xs d |j                  |j                  ||j                        S )	Nlocation	locationsbucketsviewsresource_namesAND)operator)order_bylimitparentr'   )r   MakeTimestampFilters
log_filterIsSpecifiedr   CreateResourceNameGetParentFromArgsr#   bucketviewr   	FetchLogsJoinFiltersorderr+   r'   )selfargsfilter_clausesr,   s       r   _Runz	Read._RunH   s    "77=N4??t'BN
#&&

!
!%%((.T]]L& (/			;f
 
		*	+f %%d+f!!.5AITjj**, ,r!   c                 $    | j                  |      S )zThis 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.
    )r:   )r7   r8   s     r   RunzRead.Runa   s     99T?r!   N)__name__
__module____qualname____doc__staticmethodr    r:   r<    r!   r   r   r      s$    
 "6 "6H,2
r!   r   a"          {command} reads log entries.  Log entries matching *log-filter* are
        returned in order of decreasing timestamps, most-recent entries first.
        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 Google Compute Engine instances, run:

          $ {command} "resource.type=gce_instance"

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

          $ {command} "severity>=ERROR"

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

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

        To read up to 10 log entries in your project's syslog log from Compute
        Engine instances containing payloads that include the word `SyncAddress`
        and format the output in `JSON` format, run:

          $ {command} "resource.type=gce_instance AND logName=projects/[PROJECT_ID]/logs/syslog AND textPayload:SyncAddress" --limit=10 --format=json

        To read a log entry from a folder, run:

          $ {command} "resource.type=global" --folder=[FOLDER_ID] --limit=1

        To read a log entry from a global log bucket, run:

          $ {command} --bucket=<bucket-id> --location=[LOCATION] --limit=1

        To read a log entry from the global ```_Required``` log bucket using the bucket's ```_Default``` log view:

          $ {command} "" --bucket=_Required --location=global --view=_Default --limit=1

        To read a log entry from a log bucket using the bucket's ```_AllLogs``` log view:

          $ {command} "" --bucket=[BUCKET_ID] --location=[LOCATION] --view=_AllLogs --limit=1

        To read a log entry from a log bucket using a custom log view that you have created for the bucket:

          $ {command} "" --bucket=[BUCKET_ID] --location=[LOCATION] --view=[VIEW_ID] --limit=1

        To read log entries from multiple resources, specify them as a
        comma-delimeted sequence with --resource-names. Each resource name can
        be specified either as a top-level resource (e.g.,
        projects/[PROJECT_ID], folders/[FOLDER_ID], etc.) or as a Log View
        resource (e.g.,
        projects/[PROJECT_ID]/locations/[LOCATION]/buckets/[BUCKET_NAME]/views/[VIEW_ID]).

          $ {command} "" --resource-names=[RESOURCE-1],[RESOURCE-2]

    )DESCRIPTIONEXAMPLESN)r@   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   r   googlecloudsdk.callioper   r	   googlecloudsdk.command_lib.logsr
   r   UniverseCompatibleReleaseTracksReleaseTrackALPHABETAGACommandr   detailed_helprB   r!   r   <module>rQ      s     &  ' 1 / / ( A T..33T5F5F5I5IK4<< K K`	0	: r!   