
    Mh1                        d Z ddlZddlZddlZddlmZ ddlmZmZ 	 ddl	Z	n# e
$ r dZ	Y nw xY w	 ddlZn# e
$ r dZY nw xY wddlmZmZmZmZ  ej        d          Z ej        d          Z ej        d          Zd	efd
Zded	efdZ G d dej                  Z	 ddedeej                 d	dfdZdded	dfdZdS )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                  |   	 t          t          j        d          rt          j                                        rqt          r.t	          j                     t	          j        d          dk    rdS n<t          r5t          j        t          t          j	        dt                                u rdS n# t          $ r Y nw xY wdS )Nisattycolorsr   Twrapped_stderrF)hasattrsysstderrr   curses	setuptermtigetnumcoloramagetattr
initialiseobject	Exception     K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/log.py_stderr_supports_colorr   7   s    3:x(( 		 SZ->->-@-@ 		    """?8,,q004 1  :')9688" "    4    	 5s   A*B, .;B, ,
B98B9sc                 `    	 t          |           S # t          $ r t          |           cY S w xY wN)r   UnicodeDecodeErrorrepr)r   s    r   _safe_unicoder#   J   s=    {{   Awws    --c                       e Zd ZdZdZdZej        dej        dej	        dej
        dej        diZeed	d
efdededededeeef         ddfdZdedefdZdS )LogFormatterap  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                 J   t           j                            | |           || _        i | _        |rt                      rt          t          j        d          pt          j        d          pd}|                                D ]0\  }}t          t          j
        ||          d          | j        |<   1t          j        d          }	|	t          |	d          | _        dS d| _        dS |                                D ]\  }}d	|z  | j        |<   d
| _        dS d| _        dS )aX  
        :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.   r/   r   fg_colorlevelnocodenormals
             r   r8   zLogFormatter.__init__t   s5   . 	""4"999	 	+-- 	!!?733Uvv7N7NURU%+\\^^  MGT -9Xt44g- -DL))  00%#/#@#@DLLL#%DLLL &,\\^^ A AMGT,9D,@DL))(DLLLr   recordc                 0   	 |                                 }t          |t                    sJ t          |          |_        n)# t
          $ r}d|d|j        |_        Y d }~nd }~ww xY w|                     |t          t          | j
                            |_        |j        | j        v r$| j        |j                 |_        | j        |_        ndx|_        |_        | j        |j        z  }|j        r&|j        s|                     |j                  |_        |j        ra|                                g}|                    d |j                            d          D                        d                    |          }|                    dd          S )NzBad message (z): r5   c              3   4   K   | ]}t          |          V  d S r    )r#   ).0lns     r   	<genexpr>z&LogFormatter.format.<locals>.<genexpr>   s*      QQrr**QQQQQQr   
z
    )
getMessage
isinstancer   r#   messager   __dict__
formatTimer   strr-   asctimerA   r:   r/   r>   	end_colorr9   exc_infoexc_textformatExceptionrstripextendsplitjoinreplace)r?   rD   rM   e	formattedliness         r   formatzLogFormatter.format   s   	I''))Gg77777" +733FNN 	I 	I 	IHQHHV_HHFNNNNNN	I c4<1H1HII>T\))<7FL#|F.00FL6+I/	? 	H? H"&"6"6v"G"G? 	) %%''(ELLQQV_5J5J45P5PQQQQQQ		%((I  x000s   ?A 
A(A##A()__name__
__module____qualname____doc__DEFAULT_FORMATDEFAULT_DATE_FORMATr6   DEBUGINFOWARNINGERRORCRITICALDEFAULT_COLORSrP   boolr   intr8   r   r^   r   r   r   r%   r%   Q   s         0 nN+qaq!N "*!/2 22 2 	2
 2 S#X2 
2 2 2 2h,1S ,1S ,1 ,1 ,1 ,1 ,1 ,1r   r%   optionsloggerc                    | ddl }|j        j        } | j        | j                                        dk    rdS |t          j                    }|                    t          t          | j                                                             | j        r| j	        }|dk    r3t          j
                            | j        | j        | j        d          }nV|dk    r9t          j
                            | j        | j        | j        | j        d          }nd	d
|z  z   }t#          |          |                    t'          d                     |                    |           | j        s| j        R|j
        sMt          j                    }|                    t'                                 |                    |           dS dS dS )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)rr   whenintervalrt   ru   z.The value of log_rotate_mode option should be z"size" or "time", not "%s".F)r/   )tornado.optionsrm   r6   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)rm   rn   tornadorotate_modechannelerror_messages         r   enable_pretty_loggingr      s    /)'/"7"7"9"9V"C"C~"$$
OOGGW_%:%:%<%<==>>> #-&  &:: 0 2#8 	 ;  GG F""&?? 0, 4#8  @  GG A/+=>  ]+++\666777'""" #!6!>v!>'))\^^,,,'"""""	 "?!>!>!>r   c                 4     ddl }|j        j                              dddd                                dt          dd	
                                dt          ddd                                dt
          dd
                                dt
          dd
                                dt          dd
                                dt
          dd
                                dt          dd
                                 fd           dS )aB  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   r6   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   rq   z(The mode of rotating files(time or size)c                  "    t                     S r    )r   )rm   s   r   <lambda>z(define_logging_options.<locals>.<lambda>W  s    '<W'E'E r   )ry   rm   definerk   rP   rl   add_parse_callback)rm   r   s   ` r   define_logging_optionsr   	  s    /)NN% 0     NN.  	 	 	 NN'     NN!4	     NNS";X     NN<     NN3	     NN7	     EEEEFFFFFr   )NNr    )rb   r6   logging.handlersr   tornado.escaper   tornado.utilr   r   r   ImportErrorr   typingr   r   r   r	   r{   
access_logapp_loggen_logrk   r   rP   r#   r7   r%   Loggerr   r   r   r   r   <module>r      s         



 # # # # # # 6 6 6 6 6 6 6 6OOOO   HHHMMMM   FFF - , , , , , , , , , , , W/00

'
1
2
2
'
-
.
.    &S S    C1 C1 C1 C1 C17$ C1 C1 C1N =A/# /#/#!)'.!9/#	/# /# /# /#dNG NGC NG4 NG NG NG NG NG NGs   # --6 A A 