wceyddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z m Z mZmZddlmZddlmZddlmZedd ZGd d eZy) N) namedtuple)AnyCallableDictIterableListTuple)AbstractAccessLogger) BaseRequest)StreamResponse KeyMethodz key methodceZdZUdZdddddddd d d d d ZdZejdZejdZ iZ e e e e eeffed<efdej$de 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|||tjj |}|s$|j |}|tj|<|\|_|_y)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 1/usr/lib/python3/dist-packages/aiohttp/web_log.pyr-zAccessLogger.__init__?sa J7'5599*E#22:> 5EL & &z 2*:'$-c  t}|jj|D]}|ddk(r5|j|d}t t d|dz}t ||}nP|j|d|df}t t d|dz}t |tj||d}|j||jjd|}|jjd|}||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.&NN**:6 'DAw"}"11$q': L,a*@A&{A6 #2247;T!WE L,a*@A&{I4E4Eaa4QR NN: & '^^''z: __((< 7""r6keyrequestresponsetimec@|y|jj|dS)Nz (no headers)-headersr.rJrKrLrMs r5 _format_izAccessLogger._format_ixs% ?!""3,,r6c:|jj|dSNrOrPrRs r5 _format_ozAccessLogger._format_os ##C--r6c,|y|j}||SdSrU)remote)rKrLrMips r5 _format_azAccessLogger._format_as" ? ^^^r,,r6ctjtjtj }tjj |}|tj|z }|j dS)N)secondsz[%d/%b/%Y:%H:%M:%S %z])datetimetimezone timedeltatime_modnowstrftime)rKrLrMtzra start_times r5 _format_tzAccessLogger._format_tsc   x118;L;L:LM N##B'8--d;; ""#;<)osgetpidrKrLrMs r5 _format_PzAccessLogger._format_Ps ##r6c|ydj|j|j|jj|jj S)NrOz{} {} HTTP/{}.{})formatmethodpath_qsversionmajorminorris r5 _format_rzAccessLogger._format_rsE ?!(( NN OO OO ! ! OO ! !   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 }r6c0tt|dzS)Ni@Br{ris r5 _format_DzAccessLogger._format_Ds5())r6c `|jDcgc]\}}|||||fc}}Scc}}wrt)r1)r2rKrLrMrJrms r5 _format_linezAccessLogger._format_lines0KO--X;3fWh56XXXs*c |jjtjsy |j |||}t }t }|D]O\}}|j||jtur|||</|\} } |j| i} || | <| || <Q|jj|jt|z|y#t$r|jjdYywxYw)N)extrazError in logging)r( isEnabledForloggingINFOrr:dictrAr4r|r.infor0tuple Exception exception) r2rKrLrMfmt_infovaluesrrJvaluek1k2dcts r5logzAccessLogger.logs{{'' 5  6(((DAHVFFE& $ U e$==C'!&E#J FB))B+C#CG #E"I $ KK  T--f =U  K 6 KK ! !"4 5 6sB.C$DD)*__name__ __module__ __qualname____doc__r= LOG_FORMATrecompiler;rCr'rr|r rr__annotations__rLoggerr-r/ staticmethodr r floatrSrVrZrerjrrintrvryr~rrrrrr __classcell__)r4s@r5rrs^6 !  !   ! !   NCJ LMIJ'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 RY 6;6.66RV6r6r)r]r?rrgrrMr` collectionsrtypingrrrrrr abcr web_requestr web_responser rrrr6r5rsD "==%$( {L 1 D6'D6r6