o
    "it>                     @  s  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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rXed e  edejZedejZedejZeeef Zded< 	 	dd ddZG dd dejZ dS )!z-Core functionality shared by all JSON loggers    )annotations)datetimetimezoneN)OptionalUnion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   LogDatarecordlogging.LogRecordtargetr   reservedContainer[str]rename_fieldsOptional[Dict[str, str]]returnc                 C  sP   |du ri }| j  D ]\}}||vr%t|dr|ds%|||||< q|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hasattrr2   get)r*   r,   r-   r/   keyvalue r:   U/var/www/html/premium_crap/venv/lib/python3.10/site-packages/pythonjsonlogger/core.pymerge_record_extraS   s   r<   c                      s   e Zd ZU dZded< 				d>dddddddddd		d?d!d"Zd@d%d&ZdAd(d)ZdBd,d-ZdCd0d1Z	dDd3d4Z
dBd5d6ZdEd7d8ZdF fd:d;ZdF fd<d=Z  ZS )G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 3.3*: `exc_info_as_array` and `stack_info_as_array` options are added.
    z Union[logging.PercentStyle, str]_styleN%T F)	prefixr/   rename_fields_keep_missingstatic_fieldsreserved_attrs	timestampdefaultsexc_info_as_arraystack_info_as_arrayfmt#Optional[Union[str, Sequence[str]]]datefmtOptional[str]stylestrvalidateboolrA   r/   r0   rB   rC   Optional[Dict[str, Any]]rD   Optional[Sequence[str]]rE   Union[bool, str]rF   rG   rH   r1   Nonec       	           sF  |du s	t |tr<|tjv r%tj| d |}|r|  || _|j| _n|dks+|s2|| _|| _ntd|  | _	nt |t
rNd| _t|| _t|| _	|| _|| _ dura fdd D ni | _durqfddD ni | _|| _t|	dur~|	nt| _|
| _t| j	| _| j| j |dur|ni | _|| _|| _dS )	a
  
        Args:
            fmt: String format or `Sequence` of field names of fields to log.
            datefmt: format to use when formatting `asctime` field
            style: how to extract log fields from `fmt`. Ignored if `fmt` is a `Sequence[str]`.
            validate: validate `fmt` against style, if implementing a custom `style` you
                must set this to `False`. Ignored if `fmt` is a `Sequence[str]`.
            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`.

        *Added in 4.0*:

        - `fmt` now supports comma seperated lists (`style=","`). Note that this style is specific
          to `python-json-logger` and thus care should be taken to not to pass this format to other
          logging Formatter implementations.
        - `fmt` now supports sequences of strings (e.g. lists and tuples) of field names.
        Nr   ,zStyle must be one of: '%{$,'__sequence__c                      i | ]}| | qS r:   r:   .0r8   )r/   r:   r;   
<dictcomp>       z.BaseJsonFormatter.__init__.<locals>.<dictcomp>c                   rW   r:   r:   rX   )rC   r:   r;   rZ      r[   )
isinstancerN   logging_STYLESrO   r>   _fmt
ValueErrorparse_required_fieldsr   listrK   rA   r/   rC   rB   setr&   rD   rE   _skip_fieldsupdaterF   rG   rH   )selfrI   rK   rM   rO   rA   r/   rB   rC   rD   rE   rF   rG   rH   r>   r:   )r/   rC   r;   __init__   s>   <




zBaseJsonFormatter.__init__r*   r+   c                 C  s   i }t |jtr|j}d|_n| |_d| jv r!| || j|_|j	r1|
ds1| |j	|d< |
ds>|jr>|j|d< |jrN|
dsN| |j|d< i }| ||| | |}| |S )zlFormats a log record and serializes to json

        Args:
            record: the record to format
        r@   r   r   r"   )r\   r   dictr   
getMessagerb   
formatTimerK   r   r   r7   formatExceptionr   r"   formatStack
add_fieldsprocess_log_recordserialize_log_record)rg   r*   message_dictlog_datar:   r:   r;   format   s"   




zBaseJsonFormatter.formatr%   c                 C  s   | j du rg S t| jtr/| jdkrtd| jdkr&dd | j dD S td| jdt| jtjr9t	}nt| jtj
rCt}nt| jtjrMt}n	td| jd|| j 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
        NrV   z5Must not call parse when fmt is a sequence of stringsrU   c                 S  s   g | ]
}|  r|  qS r:   )strip)rY   fieldr:   r:   r;   
<listcomp>*  s    z+BaseJsonFormatter.parse.<locals>.<listcomp>zStyle z is not supported)r_   r\   r>   rN   RuntimeErrorsplitr`   r]   StringTemplateStyleSTYLE_STRING_TEMPLATE_REGEXStrFormatStyleSTYLE_STRING_FORMAT_REGEXPercentStyleSTYLE_PERCENT_REGEXfindall)rg   formatter_style_patternr:   r:   r;   ra     s    


zBaseJsonFormatter.parserr   r)   c                 C  s   | j | | S )zReturns the final representation of the data to be logged

        Args:
            log_data: the data

        *Changed in 4.0*: `log_record` renamed to `log_data`
        )rA   jsonify_log_recordrg   rr   r:   r:   r;   rp   >  s   z&BaseJsonFormatter.serialize_log_recordDict[str, Any]rq   c                 C  s   | j D ]}| j | || |< q| jD ]}|j||| |< q| j|fD ]}| D ]\}}||| |< q,q&t||| j| j	d | j
r_t| j
trO| j
nd}tj|jtjd|| |< | jrr| j	 D ]
}||vrqd||< qgdS )a  Extract fields from a LogRecord for logging

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

        Args:
            log_data: 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})`

        *Changed in 4.0*: `log_record` renamed to `log_data`
        )r-   r/   rE   )tzN)rF   _get_renamerb   r4   r7   rC   r5   r<   re   r/   rE   r\   rN   r   fromtimestampr   r   utcrB   values)rg   rr   r*   rq   ru   	data_dictr8   r9   r:   r:   r;   rn   H  s2   

zBaseJsonFormatter.add_fieldsr8   c                 C  s   | j ||S N)r/   r7   )rg   r8   r:   r:   r;   r   w  s   zBaseJsonFormatter._get_renamec                 C  s   t  )zConvert the log data into a JSON string.

        Child classes MUST override this method.

        Args:
            log_data: the data to serialize

        *Changed in 4.0*: `log_record` renamed to `log_data`
        )NotImplementedErrorr   r:   r:   r;   r   |  s   
z$BaseJsonFormatter.jsonify_log_recordc                 C  s   |S )a  Custom processing of the data to be logged.

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

        Args:
            log_data: incoming data

        *Changed in 4.0*: `log_record` renamed to `log_data`
        r:   r   r:   r:   r;   ro     s   z$BaseJsonFormatter.process_log_recordUnion[str, list[str]]c                      t  |}| jr| S |S )zFormat and return the specified exception information.

        If exc_info_as_array is set to True, This method returns an array of strings.
        )superrl   rG   
splitlines)rg   eiexception_info_str	__class__r:   r;   rl        z!BaseJsonFormatter.formatExceptionc                   r   )zFormat and return the specified stack information.

        If stack_info_as_array is set to True, This method returns an array of strings.
        )r   rm   rH   r   )rg   r"   stack_info_strr   r:   r;   rm     r   zBaseJsonFormatter.formatStack)NNr?   T)rI   rJ   rK   rL   rM   rN   rO   rP   rA   rN   r/   r0   rB   rP   rC   rQ   rD   rR   rE   rS   rF   rQ   rG   rP   rH   rP   r1   rT   )r*   r+   r1   rN   )r1   r%   )rr   r)   r1   rN   )rr   r   r*   r+   rq   r   r1   rT   )r8   rN   r1   rN   )rr   r)   r1   r)   )r1   r   )__name__
__module____qualname____doc____annotations__rh   rs   ra   rp   rn   r   r   ro   rl   rm   __classcell__r:   r:   r   r;   r=   p   s6   
 
o
'
'


/

r=   r   )
r*   r+   r,   r   r-   r.   r/   r0   r1   r   )!r   
__future__r   r   r   r]   resystypingr   r   r   r   r	   r
   r   version_infor   typing_extensionsr&   r   appendsortcompile
IGNORECASErz   r|   r~   rN   r)   r<   	Formatterr=   r:   r:   r:   r;   <module>   s.    $
	

