
    hZ2                        S r SSKrSSKrSSKrSSKJr  SSKJrJr   SSK	r	 SSKrSSKJrJrJrJr  \R"                  " S5      r\R"                  " S5      r\R"                  " S5      rS	\4S
 jrS\S	\4S jr " S S\R2                  5      r SS\S\\R6                     S	S4S jjrSS\S	S4S jjrg! \
 a    Sr	 Nf = f! \
 a    Sr Nf = f)aH  Logging support for Tornado.

Tornado uses three logger streams:

* ``tornado.access``: Per-request logging for Tornado's HTTP servers (and
  potentially other servers in the future)
* ``tornado.application``: Logging of errors from application code (i.e.
  uncaught exceptions from callbacks)
* ``tornado.general``: General-purpose logging, including any errors
  or warnings from Tornado itself.

These streams may be configured independently using the standard library's
`logging` module.  For example, you may wish to send ``tornado.access`` logs
to a separate file for analysis.
    N)_unicode)unicode_typebasestring_type)DictAnycastOptionalztornado.accessztornado.applicationztornado.generalreturnc                      [        [        R                  S5      (       a  [        R                  R                  5       (       a}  [        (       a2  [        R
                  " 5         [        R                  " S5      S:  a  g g[        (       a5  [        R                  [        [        R                  S[        5       5      L a  gg! [         a     gf = f)Nisattycolorsr   Twrapped_stderrF)hasattrsysstderrr   curses	setuptermtigetnumcoloramagetattr
initialiseobject	Exception     ^C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\tornado/log.py_stderr_supports_colorr   7   s    3::x((SZZ->->-@-@v  "??8,q0 1  ::'')968"   
 	   		s   A<C ?C 
CCsc                 P     [        U 5      $ ! [         a    [        U 5      s $ f = fN)r   UnicodeDecodeErrorrepr)r   s    r   _safe_unicoder#   J   s)    { Aws   
 %%c                       \ rS rSrSrSrSr\R                  S\R                  S\R                  S\R                  S\R                  S	0r\\S
S\4S\S\S\S\S\\\4   SS4S jjrS\S\4S jrSrg)LogFormatterQ   a0  Log formatter used in Tornado.

Key features of this formatter are:

* Color support when logging to a terminal that supports it.
* Timestamps on every log line.
* Robust against str/bytes encoding problems.

This formatter is enabled automatically by
`tornado.options.parse_command_line` or `tornado.options.parse_config_file`
(unless ``--logging=none`` is used).

Color support on Windows versions that do not support ANSI color codes is
enabled by use of the colorama__ library. Applications that wish to use
this must first initialize colorama with a call to ``colorama.init``.
See the colorama documentation for details.

__ https://pypi.python.org/pypi/colorama

.. versionchanged:: 4.5
   Added support for ``colorama``. Changed the constructor
   signature to be compatible with `logging.config.dictConfig`.
zV%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)sz%y%m%d %H:%M:%S               %Tfmtdatefmtstylecolorr   r
   Nc                 p   [         R                  R                  XS9  Xl        0 U l        U(       a  [        5       (       a  [        b  [        R                  " S5      =(       d    [        R                  " S5      =(       d    SnUR                  5        H2  u  px[        [        R                  " Xh5      S5      U R                  U'   M4     [        R                  " S5      n	U	b  [        U	S5      U l        gSU l        gUR                  5        H  u  pxS	U-  U R                  U'   M     S
U l        gSU l        g)a  
:arg bool color: Enables color support.
:arg str fmt: Log message format.
  It will be applied to the attributes dict of log records. The
  text between ``%(color)s`` and ``%(end_color)s`` will be colored
  depending on the level if color support is on.
:arg dict colors: color mappings from logging level to terminal color
  code
:arg str datefmt: Datetime format.
  Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``.

.. versionchanged:: 3.2

   Added ``fmt`` and ``datefmt`` arguments.
)r.   Nsetafsetfr   asciisgr0 z[2;3%dmz[0m)logging	Formatter__init___fmt_colorsr   r   tigetstritemsr   tparm_normal)
selfr-   r.   r/   r0   r   fg_colorlevelnocodenormals
             r   r9   LogFormatter.__init__t   s    . 	""4"9	+--!!??73Uvv7NURU%+\\^MG -9X4g-DLL)	 &4  0%#/#@DL#%DL &,\\^MG,9D,@DLL) &4(DLr   recordc                     UR                  5       n[        U[        5      (       d   e[        U5      Ul        U R                  U[        [        U R                  5      5      Ul        UR                  U R                  ;   a0  U R                  UR                     Ul        U R                  Ul        OS=Ul        Ul        U R"                  UR                  -  nUR$                  (       a1  UR&                  (       d   U R)                  UR$                  5      Ul        UR&                  (       aS  UR+                  5       /nUR-                  S UR&                  R/                  S5       5       5        SR1                  U5      nUR3                  SS5      $ ! [
         a$  nSU< SUR                  < 3Ul         S nAGNS nAff = f)NzBad message (z): r6   c              3   8   #    U  H  n[        U5      v   M     g 7fr    )r#   ).0lns     r   	<genexpr>&LogFormatter.format.<locals>.<genexpr>   s     Q5Prr**5Ps   
z
    )
getMessage
isinstancer   r#   messager   __dict__
formatTimer   strr.   asctimerB   r;   r0   r?   	end_colorr:   exc_infoexc_textformatExceptionrstripextendsplitjoinreplace)r@   rF   rP   e	formattedliness         r   formatLogFormatter.format   sV   	I'')Gg7777" +73FN c4<<1HI>>T\\)<<7FL#||F.00FL6+II/	????"&"6"6v"G?? %%'(ELLQV__5J5J45PQQ		%(I  x00/  	I,QEV__4GHFNN	Is   7F 
F?F::F?)r;   r:   r?   )__name__
__module____qualname____firstlineno____doc__DEFAULT_FORMATDEFAULT_DATE_FORMATr7   DEBUGINFOWARNINGERRORCRITICALDEFAULT_COLORSrS   boolr   intr9   r   ra   __static_attributes__r   r   r   r%   r%   Q   s    0 nN+qaq!N "*!/22 2 	2
 2 S#X2 
2h,1S ,1S ,1r   r%   optionsloggerc                    U c  SSK nUR                  R                  n U R                  b  U R                  R                  5       S:X  a  gUc  [        R                  " 5       nUR                  [        [        U R                  R                  5       5      5        U R                  (       a  U R                  nUS:X  a?  [        R                  R                  U R                  U R                  U R                  SS9nOcUS:X  aJ  [        R                  R                  U R                  U R                  U R                   U R                  SS9nOS	S
U-  -   n[#        U5      eUR%                  ['        SS95        UR)                  U5        U R*                  (       d  U R*                  cR  UR                  (       d@  [        R,                  " 5       nUR%                  ['        5       5        UR)                  U5        ggg)zTurns on formatted logging output as configured.

This is called automatically by `tornado.options.parse_command_line`
and `tornado.options.parse_config_file`.
Nr   nonesizezutf-8)filenamemaxBytesbackupCountencodingtime)rx   whenintervalrz   r{   z.The value of log_rotate_mode option should be z"size" or "time", not "%s".F)r0   )tornado.optionsrs   r7   lower	getLoggersetLevelr   upperlog_file_prefixlog_rotate_modehandlersRotatingFileHandlerlog_file_max_sizelog_file_num_backupsTimedRotatingFileHandlerlog_rotate_whenlog_rotate_interval
ValueErrorsetFormatterr%   
addHandlerlog_to_stderrStreamHandler)rs   rt   tornadorotate_modechannelerror_messages         r   enable_pretty_loggingr      s    //))'//"7"7"9V"C~""$
OOGGW__%:%:%<=>--& &&:: 00 22#88 	 ; G F"&&?? 00,, 44#88  @ G A/+=>  ]++\67'"!6!6!>v'')\^,'"	 HW!>r   c                   ^  T c  SSK nUR                  R                  m T R                  SSSSS9  T R                  S[        SS	S
9  T R                  S[        SSSS9  T R                  S[
        SSS
9  T R                  S[
        SSS
9  T R                  S[        SSS
9  T R                  S[
        SSS
9  T R                  S[        SSS
9  T R                  U 4S j5        g)a.  Add logging-related flags to ``options``.

These options are present automatically on the default options instance;
this method is only necessary if you have created your own `.OptionParser`.

.. versionadded:: 4.2
    This function existed in prior versions but was broken and undocumented until 4.2.
Nr   r7   infozSSet the Python log level. If 'none', tornado won't touch the logging configuration.zdebug|info|warning|error|none)defaulthelpmetavarr   zSend log output to stderr (colorized if possible). By default use stderr if --log_file_prefix is not set and no other logging is configured.)typer   r   r   PATHzPath prefix for log files. Note that if you are running multiple tornado processes, log_file_prefix must be different for each of them (e.g. include the port number))r   r   r   r   r   i z%max size of log files before rolloverr   
   znumber of log files to keepr   midnightzcspecify the type of TimedRotatingFileHandler interval other options:('S', 'M', 'H', 'D', 'W0'-'W6')r   r*   z$The interval value of timed rotatingr   rw   z(The mode of rotating files(time or size)c                     > [        T 5      $ r    )r   )rs   s   r   <lambda>(define_logging_options.<locals>.<lambda>W  s    '<W'Er   )r   rs   definerp   rS   rq   add_parse_callback)rs   r   s   ` r   define_logging_optionsr   	  s.    //))NN% 0   NN.  	 NN'   NN!4	   NNS";X   NN<   NN3	   NN7	   EFr   )NNr    )rg   r7   logging.handlersr   tornado.escaper   tornado.utilr   r   r   ImportErrorr   typingr   r   r   r	   r   
access_logapp_loggen_logrp   r   rS   r#   r8   r%   Loggerr   r   r   r   r   <module>r      s     
 # 6 - , /0



1
2


-
. &S S C17$$ C1N =A/#/#!)'..!9/#	/#dNGC NG4 NGE  H
  Fs"   B5 C 5C ?C CC