bgyddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z m Z mZmZddlmZddlmZddlmZedd ZGd d eZdS) N) namedtuple)AnyCallableDictIterableListTuple)AbstractAccessLogger) BaseRequest)StreamResponse KeyMethodz key methodc(eZdZUdZdddddddd d d d d ZdZejdZejdZ iZ e e e e eeffed<efdejde ddffd Zde de e eeffdZede dededede f dZede dededede f dZedededede fdZedededede fdZedededede fd Zedededede fd!Zededededefd"Z ededededefd#Z!edededede fd$Z"edededede fd%Z#edededede fd&Z$dededede%e e e&eeege fffd'Z'dedededdfd(Z(xZ)S)) AccessLoggeraHelper object to log access. Usage: log = logging.getLogger("spam") log_format = "%a %{User-Agent}i" access_logger = AccessLogger(log, log_format) access_logger.log(request, response, time) Format: %% The percent sign %a Remote IP-address (IP-address of proxy if using reverse proxy) %t Time when the request was started to process %P The process ID of the child that serviced the request %r First line of request %s Response status code %b Size of response in bytes, including HTTP headers %T Time taken to serve the request, in seconds %Tf Time taken to serve the request, in seconds with floating fraction in .06f format %D Time taken to serve the request, in microseconds %{FOO}i request.headers['FOO'] %{FOO}o response.headers['FOO'] %{FOO}e os.environ['FOO'] remote_addressrequest_start_time process_idfirst_request_lineresponse_status response_size request_timerequest_time_fracrequest_time_microrequest_headerresponse_header) atPrsbTTfDioz/%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"z.%(\{([A-Za-z0-9\-_]+)\}([ioe])|[atPrsbOD]|Tf?)z(%[^s]) _FORMAT_CACHElogger log_formatreturnNct||tj|}|s$||}|tj|<|\|_|_dS)zInitialise the logger. logger is a logger object to be used for logging. log_format is a string with apache compatible log format description. )r)N)super__init__rr'getcompile_format _log_format_methods)selfr(r)_compiled_format __class__s F/opt/cloudlinux/venv/lib64/python3.11/site-packages/aiohttp/web_log.pyr-zAccessLogger.__init__?sv J777'599*EE F#22:>> 5EL &z 2*:'$---c Vt}|j|D]}|ddkrB|j|d}t t d|dz}t ||}nb|j|d|df}t t d|dz}t |tj||d}| ||j d|}|j d|}||fS)aTranslate log_format into form usable by modulo formatting All known atoms will be replaced with %s Also methods for formatting of those atoms will be added to _methods in appropriate order For example we have log_format = "%a %t" This format will be translated to "%s %s" Also contents of _methods will be [self._format_a, self._format_t] These method will be called and results will be passed to translated string format. Each _format_* method receive 'args' which is list of arguments given to self.log Exceptions are _format_e, _format_i and _format_o methods which also receive key name (by functools.partial) r rz _format_%sz%sz%\1) list FORMAT_REfindallLOG_FORMAT_MAPgetattrrr functoolspartialappendsub CLEANUP_RE)r2r)methodsatom format_key1m key_method format_key2s r5r/zAccessLogger.compile_formatOs.&&N**:66 ' 'DAw"}}"1$q': L,a*@AA&{A66 #247;T!WE L,a*@AA&{I4Eaa4Q4QRR NN: & & & &^''z:: _((<< 7""r6keyrequestresponsetimec@|dS|j|dS)Nz (no headers)-headersr.rJrKrLrMs r5 _format_izAccessLogger._format_ixs( ?!>""3,,,r6c8|j|dSNrOrPrRs r5 _format_ozAccessLogger._format_os ##C---r6c$|dS|j}||ndSrU)remote)rKrLrMips r5 _format_azAccessLogger._format_as! ?3 ^^rr,r6ctjtjtj }tj|}|tj|z }|dS)N)secondsz[%d/%b/%Y:%H:%M:%S %z])datetimetimezone timedeltatime_modnowstrftime)rKrLrMtzra start_times r5 _format_tzAccessLogger._format_tsi  x18;L:LMMM N N##B''8-d;;;; ""#;<<)osgetpidrKrLrMs r5 _format_PzAccessLogger._format_Ps ##r6cv|dSd|j|j|jj|jjS)NrOz{} {} HTTP/{}.{})formatmethodpath_qsversionmajorminorris r5 _format_rzAccessLogger._format_rs> ?3!(( N O O ! O !    r6c|jSN)statusris r5 _format_szAccessLogger._format_ss r6c|jSrt) body_lengthris r5 _format_bzAccessLogger._format_bs ##r6c:tt|Srtstrroundris r5 _format_TzAccessLogger._format_Ts5;;r6c d|zS)Nz%06fris r5 _format_TfzAccessLogger._format_Tfs }r6c@tt|dzS)Ni@Br{ris r5 _format_DzAccessLogger._format_Ds5(()))r6c2fd|jDS)Nc4g|]\}}||fSrr).0rJrmrKrLrMs r5 z-AccessLogger._format_line..s0XXX;3ffWh556XXXr6)r1)r2rKrLrMs ```r5 _format_linezAccessLogger._format_lines*YXXXXX$-XXXXr6c|jtjsdS ||||}t }t }|D]S\}}|||jtur|||<.|\} } | | i} || | <| || <T|j |j t|z|dS#t$r|jdYdSwxYw)N)extrazError in logging)r( isEnabledForloggingINFOrr:dictrAr4r|r.infor0tuple Exception exception) r2rKrLrMfmt_infovaluesrrJvaluek1k2dcts r5logzAccessLogger.logs&{'' 55  F 6(((DAAHVVFFFE& $ $ U e$$$=C''!&E#JJ FB))B++C#CG #E"II K  T-f =U  K K K K K 6 6 6 K ! !"4 5 5 5 5 5 5 6sB:C$$$D  D )*__name__ __module__ __qualname____doc__r= LOG_FORMATrecompiler;rCr'rr|r rr__annotations__rLoggerr-r/ staticmethodr r floatrSrVrZrerjrrintrvryr~rrrrrr __classcell__)r4s@r5rrs^6 !  !   ! !    NCJ LMMIJ''J<>M4U3Y#7889>>>AK;;w~;3;PT;;;;;; '#'#sDO7K1L'#'#'#'#R- -&-2@-HM- ---\-. .&.2@.HM. ...\. -;-.--RU---\- =;=.==RU===\= $;$.$$RU$$$\$ ; .  RU   \ ;.RU\$;$.$$RU$$$\$ ; .  RU   \ K>SV\*;*.**RU***\*Y"Y.<YDIY %X{NE&JC&OPPQ RYYYY 6;6.66RV66666666r6r)r]r?rrgrrMr` collectionsrtypingrrrrrr abcr web_requestr web_responser rrrr6r5rs  """"""================%%%%%%$$$$$$(((((( J{L 1 1 D6D6D6D6D6'D6D6D6D6D6r6