
                             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  G d de
j                         Zddde_        y)zapp logs read command.    )absolute_import)division)unicode_literals)	logs_util)common)base)flags)log)
propertiesc                   &    e Zd ZdZed        Zd Zy)Readz1Reads log entries for the current App Engine app.c                 0   t         j                  j                  |        t         j                  j                  |        t         j                  j                  |        t         j
                  j                  |        | j                  ddt        dd       y)z Register flags for this command.z--limitF   zNumber of log entries to show.)requiredtypedefaulthelpN)r	   SERVICEAddToParserVERSIONLEVELLOGSadd_argumentint)parsers    lib/surface/app/logs/read.pyArgsz	Read.Args    sl     
MMf%	MMf%	KKF#	JJ6"
	E #*J  L    c                    t        j                         }|j                  t         j                         |j                  t         j                         |j                  t         j
                         t        j                  j                  j                  j                  d      }t        j                  ||j                  |j                  |j                  |j                        }g }t!        j"                  dj%                  |      d|j&                        D ]"  }|j)                  |j+                  |             $ t-        |      D ]!  }t.        j0                  j3                  |       # y)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.
    T)r   z AND DESC)
log_filterorder_bylimitN)r   
LogPrinterRegisterFormatterFormatRequestLogEntryFormatNginxLogEntryFormatAppEntryr   VALUEScoreprojectGet
GetFilterslogsserviceversionlevelr   	FetchLogsjoinr#   appendFormatreversedr
   outPrint)selfargsprinterr+   filterslinesentrylines           r   RunzRead.Run*   s    ""$Gi==>i;;<i667$$,,00$0?G""7DIIt||#'<<=G E!!W\\'-B+1(,

4 ll7>>%()4 	ggmmD  r   N)__name__
__module____qualname____doc__staticmethodr   r@    r   r   r   r      s    9L Lr   r   z        Display the latest log entries from stdout, stderr and crash log for the
        current Google App Engine app in a human readable format. This command
        requires that the caller have the logging.logEntries.list
        permission.
    a          To display the latest entries for the current app, run:

          $ {command}

        To show only the entries with severity at `warning` or higher, run:

          $ {command} --level=warning

        To show only the entries with a specific version, run:

          $ {command} --version=v1

        To show only the 10 latest log entries for the default service, run:

          $ {command} --limit=10 --service=default

        To show only the logs from the request log for standard apps, run:

          $ {command} --logs=request_log

        To show only the logs from the request log for Flex apps, run:

          $ {command} --logs=nginx.request
    )DESCRIPTIONEXAMPLESN)rD   
__future__r   r   r   googlecloudsdk.api_lib.appr   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   googlecloudsdk.command_lib.appr	   googlecloudsdk.corer
   r   Commandr   detailed_helprF   r   r   <module>rQ      sJ     &  ' 0 1 ( 0 # *&4<< &R  r   