
    ]d"(                     D   U d Z ddlZddlZddlZddlmZmZmZmZ ddlZddl	Z	ddl
mZmZmZmZmZmZ ddlmZ ddlmZ dZeedf         ed	<   	 dd
ej        dedeeef         deeeef                  def
dZ G d dej                  Z G d dej                  ZdS )zh
This library is provided to allow standard python logging
to output log data as JSON formatted strings
    N)datedatetimetimetimezone)AnyDictOptionalUnionListTuple)istraceback)OrderedDict)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.RESERVED_ATTRSrecordtargetreservedrename_fieldsreturnc                     |i }| j                                         D ]G\  }}||vr>t          |d          r|                    d          s|||                    ||          <   H|S )ao  
    Merges extra attributes from LogRecord object into target dictionary

    :param record: logging.LogRecord
    :param target: dict to update
    :param reserved: dict or list with reserved keys to skip
    :param rename_fields: an optional dict, used to rename field names in the output.
            Rename levelname to log.level: {'levelname': 'log.level'}
    N
startswith_)__dict__itemshasattrr,   get)r&   r'   r(   r)   keyvalues         ;lib/python3.11/site-packages/pythonjsonlogger/jsonlogger.pymerge_record_extrar5      s     o++-- 7 7
UxS,//  ,,   27F=$$S--.M    c                   (     e Zd ZdZ fdZd Z xZS )JsonEncoderz<
    A custom encoder extending the default JSONEncoder
    c                 `   t          |t          t          t          f          r|                     |          S t          |          r9d                    t          j        |                    	                                S t          |          t          k    s-t          |t                    st          |          t          k    rt          |          S 	 t          t          |                               |          S # t           $ r% 	 t          |          cY S # t          $ r Y Y d S w xY ww xY w)N )
isinstancer   r   r   format_datetime_objr   join	traceback	format_tbstriptype	Exceptionstrsuperr8   default	TypeError)selfobj	__class__s     r4   rE   zJsonEncoder.default;   s   cD(D122 		++C000 	779.s3344::<<<#YY)##c9-- $99$$s88O	d++33C888 	 	 	3xx   ttt		s0   'C> >
D-	DD-
D)$D-(D))D-c                 *    |                                 S N)	isoformat)rG   rH   s     r4   r<   zJsonEncoder.format_datetime_objQ   s    }}r6   )__name__
__module____qualname____doc__rE   r<   __classcell__)rI   s   @r4   r8   r8   6   sQ             ,      r6   r8   c                       e Zd ZdZd Zd Zdee         fdZde	ee
f         dej        de	ee
f         dd	fd
Zd Zd Zd Zde	ee
f         defdZdej        defdZd	S )JsonFormatterz
    A custom formatter to format logging records as json strings.
    Extra values will be formatted as str() if not supported by
    json default encoder
    c                    |                      |                    dd                    | _        |                      |                    dd                    | _        |                      |                    dt          j                            | _        |                    dd          | _        |                    dd          | _        |                    dd	          | _	        |                    d
i           | _
        |                    di           | _        |                    dt                    }t          t          ||                    | _        |                    dd          | _        t#          j        j        | g|R i | | j        s| j        st(          | _        |                                 | _        t          t          | j        | j                            | _        | j                            | j                   dS )a	  
        :param json_default: a function for encoding non-standard objects
            as outlined in https://docs.python.org/3/library/json.html
        :param json_encoder: optional custom encoder
        :param json_serializer: a :meth:`json.dumps`-compatible callable
            that will be used to serialize the log record.
        :param json_indent: an optional :meth:`json.dumps`-compatible numeric value
            that will be used to customize the indent of the output json.
        :param prefix: an optional string prefix added at the beginning of
            the formatted string
        :param rename_fields: an optional dict, used to rename field names in the output.
            Rename message to @message: {'message': '@message'}
        :param static_fields: an optional dict, used to add fields with static values to all logs
        :param json_indent: indent parameter for json.dumps
        :param json_ensure_ascii: ensure_ascii parameter for json.dumps
        :param reserved_attrs: an optional list of fields that will be skipped when
            outputting json log record. Defaults to all log record attributes:
            http://docs.python.org/library/logging.html#logrecord-attributes
        :param 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.
        json_defaultNjson_encoderjson_serializerjson_indentjson_ensure_asciiTprefixr:   r)   static_fieldsreserved_attrs	timestampF)
_str_to_fnpoprU   rV   jsondumpsrW   rX   rY   rZ   r)   r[   r%   dictzipr\   r]   logging	Formatter__init__r8   parse_required_fields_skip_fieldsupdate)rG   r   kwargsr\   s       r4   rf   zJsonFormatter.__init__\   s   0 !OOFJJ~t,L,LMM OOFJJ~t,L,LMM#vzz:KTZ/X/XYY!::mT::!',?!F!Fjj2..#ZZ<<#ZZ<<$4nEE"3~~#F#FGGK77 	"49$999&999  	,): 	, +D $

 T%:%)%:"< "< = =  !455555r6   c                     t          |t                    s|S |                    d          \  }}}t          j        |          }t          ||          S )a  
        If the argument is not a string, return whatever was passed in.
        Parses a string such as package.module.function, imports the module
        and returns the function.

        :param fn_as_str: The string to parse. If not a string, return it.
        .)r;   rC   
rpartition	importlibimport_modulegetattr)rG   	fn_as_strpathr-   functionr   s         r4   r^   zJsonFormatter._str_to_fn   sV     )S)) 	%0055a(..vx(((r6   r*   c                    t          | j        t          j                  r t	          j        dt          j                  }nt          | j        t          j                  r t	          j        dt          j                  }nVt          | j        t          j                  r t	          j        dt          j                  }nt          d| j
        z            | j
        r|                    | j
                  S g S )z
        Parses format string looking for substitutions

        This method is responsible for returning a list of fields (as strings)
        to include in all log messages.
        z\$\{(.+?)\}z	\{(.+?)\}z
%\((.+?)\)zInvalid format: %s)r;   _stylerd   StringTemplateStylerecompile
IGNORECASEStrFormatStylePercentStyle
ValueError_fmtfindall)rG   formatter_style_patterns     r4   rg   zJsonFormatter.parse   s     dk7#>?? 		?&(j&O&O##W%;<< 	?&(jr}&M&M## W%9:: 	?&(j&N&N##1DI=>>>9 	*2249===Ir6   
log_recordr&   message_dictNc                    | j         D ]}|j                            |          ||<    |                    | j                   |                    |           t          ||| j        | j                   | j        rNt          | j                  t          k    r| j        nd}t          j        |j        t          j                  ||<   |                     |           dS )zS
        Override this method to implement custom logic for adding fields.
        )r(   r)   r]   )tzN)rh   r.   r1   rj   r[   r5   ri   r)   r]   rA   rC   r   fromtimestampr   r   utc_perform_rename_log_fields)rG   r   r&   r   fieldr2   s         r4   
add_fieldszJsonFormatter.add_fields   s     * 	; 	;E & 3 3E : :Ju$,---,'''6:8IY]Ykllll> 	V$($8$8C$?$?$..[C&4V^UUUJsO''
33333r6   c                 `    | j                                         D ]\  }}||         ||<   ||= d S rK   )r)   r/   )rG   r   old_field_namenew_field_names       r4   r   z(JsonFormatter._perform_rename_log_fields   sI    .2.@.F.F.H.H 	+ 	+*NN)3N)CJ~&>**	+ 	+r6   c                     |S )zl
        Override this method to implement custom logic
        on the possibly ordered dictionary.
         rG   r   s     r4   process_log_recordz JsonFormatter.process_log_record   s
    
 r6   c                 ^    |                      || j        | j        | j        | j                  S )z(Returns a json string of the log record.)rE   clsindentensure_ascii)rW   rU   rV   rX   rY   r   s     r4   jsonify_log_recordz JsonFormatter.jsonify_log_record   s<    ##J,0,=(,(9+/+;151G	 $ I I 	Ir6   c                 >    | j         |                     |          S )z3Returns the final representation of the log record.)rZ   r   r   s     r4   serialize_log_recordz"JsonFormatter.serialize_log_record   s"    d&=&=j&I&I&IJJr6   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<   t                      }|                     |||           |                     |          }|                     |          S )z+Formats a log record and serializes to jsonr:   r   r   r"   )r;   r   rb   r   
getMessagerh   
formatTimedatefmtr   r   r1   formatExceptionr   r"   formatStackr   r   r   r   )rG   r&   r   r   s       r4   formatzJsonFormatter.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&%0]]

FL999,,Z88
((444r6   )rM   rN   rO   rP   rf   r^   r   rC   rg   r   r   rd   	LogRecordr   r   r   r   r   r   r   r6   r4   rS   rS   U   s*        ,6 ,6 ,6\) ) )tCy    .4T#s(^ 4W=N 4^bcfhkck^l 4qu 4 4 4 4"+ + +
  I I IKtCH~ K# K K K K5W. 53 5 5 5 5 5 5r6   rS   rK   )rP   rd   r`   rx   r   r   r   r   r>   ro   typingr   r   r	   r
   r   r   inspectr   collectionsr   r%   rC   __annotations__r   r5   JSONEncoderr8   re   rS   r   r6   r4   <module>r      s       				 3 3 3 3 3 3 3 3 3 3 3 3         : : : : : : : : : : : : : : : :       # # # # # ##Lc3h L L L .2	  D$J DSM*	
 
   4    $"   >a5 a5 a5 a5 a5G% a5 a5 a5 a5 a5r6   