
    Mh8                    &   U d Z ddlmZ ddlmZmZ ddlZddlZddlZddlZddl	m
Z
mZmZmZmZmZmZmZ ej        dk    rddl	mZ nddlmZ g dZd	ed
<   	 ej        dk    r)e                    d           e                                  ej        dej                  Z ej        dej                  Z ej        dej                  Ze
eeef                  Zded<   	 eeef         Z ded<   	 d"dZ!	 d#d$dZ" G d  d!ej#                  Z$dS )%z-Core functionality shared by all JSON loggers    )annotations)datetimetimezoneN)OptionalUnionCallableListDict	ContainerAnySequence)   
   )	TypeAlias)argsasctimecreatedexc_infoexc_textfilenamefuncName	levelnamelevelnolinenomodulemsecsmessagemsgnamepathnameprocessprocessNamerelativeCreated
stack_infothread
threadName	List[str]RESERVED_ATTRS)r      taskNamez\$\{(.+?)\}z	\{(.+?)\}z
%\((.+?)\)r   OptionalCallableOrStr	LogRecordobjr   returnc                    t          | t                    s| S |                     dd          \  }}t          t	          j        |          |          S )zImport strings to an object, leaving non-strings as-is.

    Args:
        obj: the object or string to process

    *New in 3.1*
    .   )
isinstancestrrsplitgetattr	importlibimport_module)r-   module_nameattribute_names      U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pythonjsonlogger/core.pystr_to_objectr;   T   sN     c3 
"%**S!"4"4K9*;77HHH    recordlogging.LogRecordtargetr
   reservedContainer[str]rename_fieldsOptional[Dict[str, str]]c                    |i }| j                                         D ]G\  }}||vr>t          |d          r|                    d          s|||                    ||          <   H|S )a  
    Merges extra attributes from LogRecord object into target dictionary

    Args:
        record: logging.LogRecord
        target: dict to update
        reserved: dict or list with reserved keys to skip
        rename_fields: an optional dict, used to rename field names in the output.
            e.g. Rename `levelname` to `log.level`: `{'levelname': 'log.level'}`

    *Changed in 3.1*: `reserved` is now `Container[str]`.
    N
startswith_)__dict__itemshasattrrE   get)r=   r?   r@   rB   keyvalues         r:   merge_record_extrarM   d   s|    $ o++-- 8 8
Uh\(B(Bs~~VYGZGZ27F=$$S#../Mr<   c                       e Zd ZU dZded<   	 	 	 	 d3dddddddddd		d4d Zd5d#Zd6d%Zd7d(Zd8d+Z	d9d-Z
d7d.Zd:d/Zd; fd1Zd; fd2Z xZS )<BaseJsonFormatterzBase class for all formatters

    Must not be used directly.

    *New in 3.1*

    *Changed in 3.2*: `defaults` argument is no longer ignored.

    *Added in UNRELEASED*: `exc_info_as_array` and `stack_info_as_array` options are added.
    z Union[logging.PercentStyle, str]_styleN%T F)	prefixrB   rename_fields_keep_missingstatic_fieldsreserved_attrs	timestampdefaultsexc_info_as_arraystack_info_as_arrayfmtOptional[str]datefmtstyler3   validateboolrS   rB   rC   rT   rU   Optional[Dict[str, Any]]rV   Optional[Sequence[str]]rW   Union[bool, str]rX   rY   rZ   r.   Nonec       	           |t           j        v rJt          j        |         d         |          }|r|                                 || _        |j        | _        nR|s|| _        || _        nAt          dd                    t           j                                                             || _        || _	        ||ni | _
        || _        ||ni | _        t          |	|	nt                    | _        |
| _        |                                 | _        t          | j                  | _        | j                            | j                   ||ni | _        || _        || _        dS )a  
        Args:
            fmt: string representing fields to log
            datefmt: format to use when formatting `asctime` field
            style: how to extract log fields from `fmt`
            validate: validate `fmt` against style, if implementing a custom `style` you
                must set this to `False`.
            defaults: a dictionary containing default fields that are added before all other fields and
                may be overridden. The supplied fields are still subject to `rename_fields`.
            prefix: an optional string prefix added at the beginning of
                the formatted string
            rename_fields: an optional dict, used to rename field names in the output.
                Rename `message` to `@message`: `{'message': '@message'}`
            rename_fields_keep_missing: When renaming fields, include missing fields in the output.
            static_fields: an optional dict, used to add fields with static values to all logs
            reserved_attrs: an optional list of fields that will be skipped when
                outputting json log record. Defaults to [all log record attributes][pythonjsonlogger.core.RESERVED_ATTRS].
            timestamp: an optional string/boolean field to add a timestamp when
                outputting the json log record. If string is passed, timestamp will be added
                to log record using string as key. If True boolean is passed, timestamp key
                will be "timestamp". Defaults to False/off.
            exc_info_as_array: break the exc_info into a list of lines based on line breaks.
            stack_info_as_array: break the stack_info into a list of lines based on line breaks.

        *Changed in 3.1*:

        - you can now use custom values for style by setting validate to `False`.
          The value is stored in `self._style` as a string. The `parse` method will need to be
          overridden in order to support the new style.
        - Renaming fields now preserves the order that fields were added in and avoids adding
          missing fields. The original behaviour, missing fields have a value of `None`, is still
          available by setting `rename_fields_keep_missing` to `True`.
        r   zStyle must be one of: ,N)logging_STYLESr_   rP   _fmt
ValueErrorjoinkeysr]   rS   rB   rT   rU   setr(   rV   rW   parse_required_fields_skip_fieldsupdaterX   rY   rZ   )selfr[   r]   r^   r_   rS   rB   rT   rU   rV   rW   rX   rY   rZ   rP   s                  r:   __init__zBaseJsonFormatter.__init__   s^   j GO##_U+A.s33F "!!! DKDII 	ZDKDII Xchhw?S?S?U?U6V6VXXYYY .;.G]]R*D'.;.G]]R!N4N..Tbcc" $

 566  !4555$,$8b!2#6 r<   r=   r>   c                   i }t          |j        t                    r|j        }d|_        n|                                |_        d| j        v r |                     || j                  |_        |j	        r2|
                    d          s|                     |j	                  |d<   |
                    d          s|j        r
|j        |d<   |j        r2|
                    d          s|                     |j                  |d<   i }|                     |||           |                     |          }|                     |          S )zlFormats a log record and serializes to json

        Args:
            record: the record to format
        rR   r   r   r$   )r2   r   dictr   
getMessagero   
formatTimer]   r   r   rJ   formatExceptionr   r$   formatStack
add_fieldsprocess_log_recordserialize_log_record)rr   r=   message_dict
log_records       r:   formatzBaseJsonFormatter.format   sR    (* fj$'' 	1!:LFNN#..00FN ---!__VT\BBFN ? 	M<#3#3J#?#? 	M'+';';FO'L'LL$
++ 	7 	7'-L$  	M\%5%5l%C%C 	M)-)9)9&:K)L)LL& "

FL999,,Z88
((444r<   r'   c                b   t          | j        t          j                  rt          }nft          | j        t          j                  rt          }n?t          | j        t          j                  rt          }nt          d| j        d          | j
        r|                    | j
                  S g S )a=  Parses format string looking for substitutions

        This method is responsible for returning a list of fields (as strings)
        to include in all log messages.

        You can support custom styles by overriding this method.

        Returns:
            list of fields to be extracted and serialized
        zStyle z is not supported)r2   rP   rg   StringTemplateStyleSTYLE_STRING_TEMPLATE_REGEXStrFormatStyleSTYLE_STRING_FORMAT_REGEXPercentStyleSTYLE_PERCENT_REGEXrj   ri   findall)rr   formatter_style_patterns     r:   rn   zBaseJsonFormatter.parse  s     dk7#>?? 	H&A##W%;<< 		H&?##W%9:: 	H ':## FdkFFFGGG9 	>*2249===	r<   r~   r,   c                <    | j         |                     |          z   S )zrReturns the final representation of the log record.

        Args:
            log_record: the log record
        )rS   jsonify_log_recordrr   r~   s     r:   r|   z&BaseJsonFormatter.serialize_log_record-  s     {T44Z@@@@r<   Dict[str, Any]r}   c                   | j         D ]%}| j         |         ||                     |          <   &| j        D ]2}|j                            |          ||                     |          <   3| j        |fD ]4}|                                D ]\  }}|||                     |          <   5t          ||| j        | j	                   | j
        r^t          | j
        t                    r| j
        nd}t          j        |j        t           j                  ||                     |          <   | j        r%| j	                                        D ]}||vrd||<   dS )a  Extract fields from a LogRecord for logging

        This method can be overridden to implement custom logic for adding fields.

        Args:
            log_record: data that will be logged
            record: the record to extract data from
            message_dict: dictionary that was logged instead of a message. e.g
                `logger.info({"is_this_message_dict": True})`
        )r@   rB   rW   )tzN)rX   _get_renamero   rG   rJ   rU   rH   rM   rp   rB   rW   r2   r3   r   fromtimestampr   r   utcrT   values)rr   r~   r=   r}   field	data_dictrK   rL   s           r:   rz   zBaseJsonFormatter.add_fields5  s     ] 	G 	GE26-2FJt''..//* 	M 	ME28/2E2Ee2L2LJt''..//,l; 	: 	:I'oo// : :
U49
4++C0011: 	&,		
 	
 	
 	
 > 	$.t~s$C$CT$..C080F8<1 1 1Jt'',,- * 	-+2244 - -
**(,Ju%r<   rK   c                8    | j                             ||          S N)rB   rJ   )rr   rK   s     r:   r   zBaseJsonFormatter._get_renameb  s    !%%c3///r<   c                    t                      )zConvert this log record into a JSON string.

        Child classes MUST override this method.

        Args:
            log_record: the data to serialize
        )NotImplementedErrorr   s     r:   r   z$BaseJsonFormatter.jsonify_log_recordg  s     "###r<   c                    |S )zCustom processing of the log record.

        Child classes can override this method to alter the log record before it
        is serialized.

        Args:
            log_record: incoming data
         r   s     r:   r{   z$BaseJsonFormatter.process_log_recordq  s
     r<   Union[str, list[str]]c                    t                                          |          }| j        r|                                n|S )zFormat and return the specified exception information.

        If exc_info_as_array is set to True, This method returns an array of strings.
        )superrx   rY   
splitlines)rr   eiexception_info_str	__class__s      r:   rx   z!BaseJsonFormatter.formatException|  s>    
 #WW44R88262H`!,,...N``r<   c                    t                                          |          }| j        r|                                n|S )zFormat and return the specified stack information.

        If stack_info_as_array is set to True, This method returns an array of strings.
        )r   ry   rZ   r   )rr   r$   stack_info_strr   s      r:   ry   zBaseJsonFormatter.formatStack  s;    
 ,,Z88.2.FZ~((***NZr<   )NNrQ   T)r[   r\   r]   r\   r^   r3   r_   r`   rS   r3   rB   rC   rT   r`   rU   ra   rV   rb   rW   rc   rX   ra   rY   r`   rZ   r`   r.   rd   )r=   r>   r.   r3   )r.   r'   )r~   r,   r.   r3   )r~   r   r=   r>   r}   r   r.   rd   )rK   r3   r.   r3   )r~   r,   r.   r,   )r.   r   )__name__
__module____qualname____doc____annotations__rs   r   rn   r|   rz   r   r   r{   rx   ry   __classcell__)r   s   @r:   rO   rO      sm        	 	 -,,, "!%T 26+02626&+-1"'$)T T T T T Tl#5 #5 #5 #5N   <A A A A+ + + +Z0 0 0 0
$ $ $ $	 	 	 	a a a a a a[ [ [ [ [ [ [ [ [ [r<   rO   )r-   r   r.   r   r   )
r=   r>   r?   r
   r@   rA   rB   rC   r.   r
   )%r   
__future__r   r   r   r6   rg   resystypingr   r   r   r	   r
   r   r   r   version_infor   typing_extensionsr(   r   appendsortcompile
IGNORECASEr   r   r   r3   r+   r,   r;   rM   	FormatterrO   r   r<   r:   <module>r      s:   3 3 3
 # " " " " " ( ' ' ' ' ' ' '      				 



 R R R R R R R R R R R R R R R R R R R Rw       ++++++      0	 w*%%% )bjGG &BJ|R]CC  bj>>  $,E(C-,@#A  A A A A CH~	 % % % % 
I I I I( /3	    :I[ I[ I[ I[ I[) I[ I[ I[ I[ I[r<   