
    "he              	         d Z ddlmZ ddlZddlZddl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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 dd	lmZ dd
lmZ ddlmZmZ ddlmZmZmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% ddl
m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ g dZ,ejZ                  dd-dZ. e/       Z0 G d dejb                        Z2 G d de      Z3d.dZ4 G d d      Z5 G d d      Z6 G d d      Z7	 	 	 	 	 	 	 	 d/dZ8	 	 	 	 	 	 	 	 d/d Z9	 	 	 	 	 	 	 	 d/d!Z: ejv                  d"dd#dd$d%d      jx                  j{                         Z> G d& d'      Z?d(Z@	 	 	 	 	 	 	 	 d0d)ZA	 	 	 	 	 	 	 	 d1d*ZB G d+ d,ej                        ZDy)2z
Processors and helpers specific to the :mod:`logging` module from the `Python
standard library <https://docs.python.org/>`_.

See also :doc:`structlog's standard library support <standard-library>`.
    )annotationsN)partial)AnyCallable
CollectionDictIterableSequencecast)      )Self   )_config)BoundLoggerBase)_find_first_app_frame_and_name_format_stack)LEVEL_TO_NAMENAME_TO_LEVELadd_log_level)_ASYNC_CALLING_STACKmerge_contextvars)	DropEvent)StackInfoRenderer)Context	EventDictExcInfo	ProcessorProcessorReturnValueWrappedLogger)BoundLogger
ExtraAdderLoggerFactoryPositionalArgumentsFormatterProcessorFormatterr   add_log_level_numberadd_logger_namefilter_by_level
get_loggerrecreate_defaultsrender_to_log_args_and_kwargsrender_to_log_kwargs)	log_levelc           
     X   | +ddi}t        j                  d	dt        j                  | d| t	        j
                          t	        j                  t               t        t        t        t               t        j                  d   t        j                  d   gt        t                      y)
a  
    Recreate defaults on top of standard library's logging.

    The output looks the same, but goes through `logging`.

    As with vanilla defaults, the backwards-compatibility guarantees don't
    apply to the settings applied here.

    Args:
        log_level:
            If `None`, don't configure standard library logging **at all**.

            Otherwise configure it to log to `sys.stdout` at *log_level*
            (``logging.NOTSET`` being the default).

            If you need more control over `logging`, pass `None` here and
            configure it yourself.

    .. versionadded:: 22.1.0
    .. versionchanged:: 23.3.0 Added `add_logger_name`.
    .. versionchanged:: 25.1.0 Added `PositionalArgumentsFormatter`.
    NforceT%(message)s)formatstreamlevel)
processorswrapper_classlogger_factory )loggingbasicConfigsysstdoutr   reset_defaults	configurer$   r   r   r'   r   _BUILTIN_DEFAULT_PROCESSORSr!   r#   )r-   kws     M/var/www/html/sandstorm/venv/lib/python3.12/site-packages/structlog/stdlib.pyr*   r*   A   s    . t_ 	
 ::	
 		
 (*//3//3
 "$    c                  &    e Zd ZdZ	 d	 	 	 	 	 ddZy)_FixedFindCallerLoggerzi
    Change the behavior of `logging.Logger.findCaller` to cope with
    *structlog*'s extra frames.
    c                    t        dg      \  }}|rt        |      nd}|j                  j                  |j                  |j                  j
                  |fS )z
        Finds the first caller frame outside of structlog so that the caller
        info is populated for wrapping stdlib.

        This logger gets set as the default one when using LoggerFactory.
        r:   N)r   r   f_codeco_filenamef_linenoco_name)self
stack_info
stacklevelfnamesinfos         rB   
findCallerz!_FixedFindCallerLogger.findCaller{   sI     1)=4$.a Dxx##QZZ1A1A5HHrC   N)Fr   )rL   boolrM   intreturn tuple[str, int, str, str | None])__name__
__module____qualname____doc__rQ   r9   rC   rB   rE   rE   u   s-     ;<II47I	)IrC   rE   c                  X    e Zd ZU dZded<   d+ fdZd, fdZd, fdZd+ fdZd-d.dZ	d-d.d	Z
d-d.d
ZeZd-d.dZd-d.dZd-d.dZ	 d-	 	 	 	 	 	 	 d.dZ	 d-	 	 	 	 	 	 	 	 	 d/dZ	 d-	 	 	 	 	 	 	 	 	 d0 fdZed1d       Zed2d       Zed3d       Zed4d       Zed3d       Zed2d       Zd5dZ	 d6	 	 	 d7dZ	 	 d8	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d9dZd:dZd;dZd;dZd4dZ d:dZ!d2dZ"d<d Z#d=d!Z$	 	 	 	 	 	 	 	 	 	 d>d"Z%d?d#Z&d?d$Z'd?d%Z(d?d&Z)d?d'Z*d?d(Z+d?d)Z,	 	 	 	 	 	 	 	 	 	 d@d*Z- xZ.S )Ar!   a  
    Python Standard Library version of `structlog.BoundLogger`.

    Works exactly like the generic one except that it takes advantage of
    knowing the logging methods in advance.

    Use it like::

        structlog.configure(
            wrapper_class=structlog.stdlib.BoundLogger,
        )

    It also contains a bunch of properties that pass-through to the wrapped
    `logging.Logger` which should make it work as a drop-in replacement.

    .. versionadded:: 23.1.0
       Async variants `alog()`, `adebug()`, `ainfo()`, and so forth.

    .. versionchanged:: 24.2.0
        Callsite parameters are now also collected by
        `structlog.processors.CallsiteParameterAdder` for async log methods.
    logging.Logger_loggerc                "    t        |   di |S )zS
        Return a new logger with *new_values* added to the existing ones.
        r9   )superbindrK   
new_values	__class__s     rB   r_   zBoundLogger.bind   s     w|)j))rC   c                    t        |   | S )z
        Return a new logger with *keys* removed from the context.

        Raises:
            KeyError: If the key is not part of the context.
        )r^   unbindrK   keysrb   s     rB   rd   zBoundLogger.unbind   s     w~t$$rC   c                    t        |   | S )zs
        Like :meth:`unbind`, but best effort: missing keys are ignored.

        .. versionadded:: 18.2.0
        )r^   
try_unbindre   s     rB   rh   zBoundLogger.try_unbind   s     w!4((rC   c                "    t        |   di |S )z
        Clear context and binds *initial_values* using `bind`.

        Only necessary with dict implementations that keep global state like
        those wrapped by `structlog.threadlocal.wrap_dict` when threads
        are reused.
        r9   )r^   newr`   s     rB   rj   zBoundLogger.new   s     w{(Z((rC   c                0     | j                   d|g|i |S )zP
        Process event and call `logging.Logger.debug` with the result.
        debug_proxy_to_loggerrK   eventargsrA   s       rB   rl   zBoundLogger.debug   #     %t$$WeAdAbAArC   c                0     | j                   d|g|i |S )zO
        Process event and call `logging.Logger.info` with the result.
        inform   ro   s       rB   rt   zBoundLogger.info   s#     %t$$VU@T@R@@rC   c                0     | j                   d|g|i |S )zR
        Process event and call `logging.Logger.warning` with the result.
        warningrm   ro   s       rB   rv   zBoundLogger.warning   s#     %t$$YCCCCrC   c                0     | j                   d|g|i |S )zP
        Process event and call `logging.Logger.error` with the result.
        errorrm   ro   s       rB   rx   zBoundLogger.error   rr   rC   c                0     | j                   d|g|i |S zS
        Process event and call `logging.Logger.critical` with the result.
        criticalrm   ro   s       rB   r{   zBoundLogger.critical   #     %t$$ZDDDDrC   c                0     | j                   d|g|i |S rz   rm   ro   s       rB   fatalzBoundLogger.fatal   r|   rC   c                T    |j                  dd        | j                  d|g|i |S )z
        Process event and call `logging.Logger.exception` with the result,
        after setting ``exc_info`` to `True` if it's not already set.
        exc_infoT	exception)
setdefaultrn   ro   s       rB   r   zBoundLogger.exception   s1     	j$'$t$$[%E$E"EErC   c                >     | j                   t        |   |g|i |S )zg
        Process *event* and call the appropriate logging method depending on
        *level*.
        )rn   r   rK   r3   rp   rq   rA   s        rB   logzBoundLogger.log   s(     %t$$]5%95N4N2NNrC   c                6    |r||d<   t        |   |fd|i|S )a  
        Propagate a method call to the wrapped logger.

        This is the same as the superclass implementation, except that
        it also preserves positional arguments in the ``event_dict`` so
        that the stdlib's support for format strings can be used.
        positional_argsrp   )r^   rn   )rK   method_namerp   
event_argsevent_kwrb   s        rB   rn   zBoundLogger._proxy_to_logger   s-     *4H&'w'M5MHMMrC   c                .    | j                   j                  S )z5
        Returns :attr:`logging.Logger.name`
        )r\   rO   rK   s    rB   rO   zBoundLogger.name  s    
 ||   rC   c                .    | j                   j                  S )z6
        Returns :attr:`logging.Logger.level`
        )r\   r3   r   s    rB   r3   zBoundLogger.level  s    
 ||!!!rC   c                .    | j                   j                  S )z7
        Returns :attr:`logging.Logger.parent`
        )r\   parentr   s    rB   r   zBoundLogger.parent#  s    
 ||"""rC   c                .    | j                   j                  S )z:
        Returns :attr:`logging.Logger.propagate`
        )r\   	propagater   s    rB   r   zBoundLogger.propagate*  s    
 ||%%%rC   c                .    | j                   j                  S )z9
        Returns :attr:`logging.Logger.handlers`
        )r\   handlersr   s    rB   r   zBoundLogger.handlers1      
 ||$$$rC   c                .    | j                   j                  S )z9
        Returns :attr:`logging.Logger.disabled`
        )r\   disabledr   s    rB   r   zBoundLogger.disabled8  r   rC   c                :    | j                   j                  |       y)zR
        Calls :meth:`logging.Logger.setLevel` with unmodified arguments.
        N)r\   setLevelrK   r3   s     rB   r   zBoundLogger.setLevel?  s     	e$rC   c                :    | j                   j                  |      S )zT
        Calls :meth:`logging.Logger.findCaller` with unmodified arguments.
        )rL   )r\   rQ   )rK   rL   s     rB   rQ   zBoundLogger.findCallerE  s     ||&&*&==rC   c
                J    | j                   j                  |||||||||		      S )zT
        Calls :meth:`logging.Logger.makeRecord` with unmodified arguments.
        )funcextra)r\   
makeRecord)
rK   rO   r3   fnlnomsgrq   r   r   r   s
             rB   r   zBoundLogger.makeRecordM  s3     ||&&%S#tXD ' 
 	
rC   c                :    | j                   j                  |       y)zP
        Calls :meth:`logging.Logger.handle` with unmodified arguments.
        N)r\   handlerK   records     rB   r   zBoundLogger.handle`  s     	F#rC   c                :    | j                   j                  |       y)zT
        Calls :meth:`logging.Logger.addHandler` with unmodified arguments.
        N)r\   
addHandlerrK   hdlrs     rB   r   zBoundLogger.addHandlerf  s     	%rC   c                :    | j                   j                  |       y)zW
        Calls :meth:`logging.Logger.removeHandler` with unmodified arguments.
        N)r\   removeHandlerr   s     rB   r   zBoundLogger.removeHandlerl  s     	""4(rC   c                6    | j                   j                         S )zw
        Calls :meth:`logging.Logger.hasHandlers` with unmodified arguments.

        Exists only in Python 3.
        )r\   hasHandlersr   s    rB   r   zBoundLogger.hasHandlersr  s     ||''))rC   c                :    | j                   j                  |       y)zV
        Calls :meth:`logging.Logger.callHandlers` with unmodified arguments.
        N)r\   callHandlersr   s     rB   r   zBoundLogger.callHandlersz  s     	!!&)rC   c                6    | j                   j                         S )zc
        Calls :meth:`logging.Logger.getEffectiveLevel` with unmodified
        arguments.
        )r\   getEffectiveLevelr   s    rB   r   zBoundLogger.getEffectiveLevel  s    
 ||--//rC   c                8    | j                   j                  |      S )zV
        Calls :meth:`logging.Logger.isEnabledFor` with unmodified arguments.
        )r\   isEnabledForr   s     rB   r   zBoundLogger.isEnabledFor  s     ||((//rC   c                8    | j                   j                  |      S )zR
        Calls :meth:`logging.Logger.getChild` with unmodified arguments.
        )r\   getChild)rK   suffixs     rB   r   zBoundLogger.getChild  s     ||$$V,,rC   c                ~  K   t        j                  t        j                         j                  j                        }t        j                         	 t        j                         j                  dfd       d{    t        j                  |       y7 # t        j                  |       w xY ww)S
        Merge contextvars and log using the sync logger in a thread pool.
        Nc                 2    j                   fd      S )Nc                      g i S Nr9   rq   rp   rA   meths   rB   <lambda>zABoundLogger._dispatch_to_sync.<locals>.<lambda>.<locals>.<lambda>      U(@T(@R(@ rC   runrq   ctxrp   rA   r   s   rB   r   z/BoundLogger._dispatch_to_sync.<locals>.<lambda>       @A rC   )r   setr<   	_getframef_backcontextvarscopy_contextasyncioget_running_looprun_in_executorresetrK   r   rp   rq   rA   	scs_tokenr   s    ```` @rB   _dispatch_to_synczBoundLogger._dispatch_to_sync  s      ),,S]]_-C-C-J-JK	&&(	2**,<<A  
 !&&y1
 !&&y1s0   AB=.B# B!B# B=!B# #B::B=c                \   K   | j                  | j                  |||       d{    y7 w)zq
        Log using `debug()`, but asynchronously in a separate thread.

        .. versionadded:: 23.1.0
        N)r   rl   ro   s       rB   adebugzBoundLogger.adebug  &      $$TZZbAAA   ",*,c                \   K   | j                  | j                  |||       d{    y7 w)zp
        Log using `info()`, but asynchronously in a separate thread.

        .. versionadded:: 23.1.0
        N)r   rt   ro   s       rB   ainfozBoundLogger.ainfo  s&      $$TYYtR@@@r   c                \   K   | j                  | j                  |||       d{    y7 w)zs
        Log using `warning()`, but asynchronously in a separate thread.

        .. versionadded:: 23.1.0
        N)r   rv   ro   s       rB   awarningzBoundLogger.awarning  s&      $$T\\5$CCCr   c                \   K   | j                  | j                  |||       d{    y7 w)zq
        Log using `error()`, but asynchronously in a separate thread.

        .. versionadded:: 23.1.0
        N)r   rx   ro   s       rB   aerrorzBoundLogger.aerror  r   r   c                \   K   | j                  | j                  |||       d{    y7 wzt
        Log using `critical()`, but asynchronously in a separate thread.

        .. versionadded:: 23.1.0
        Nr   r{   ro   s       rB   	acriticalzBoundLogger.acritical  &      $$T]]E4DDDr   c                \   K   | j                  | j                  |||       d{    y7 wr   r   ro   s       rB   afatalzBoundLogger.afatal  r   r   c                   K   |j                  dd      du r(|j                  d      t        j                         |d<   | j                  | j                  |||       d{    y7 w)zu
        Log using `exception()`, but asynchronously in a separate thread.

        .. versionadded:: 23.1.0
        r   Tr   N)getr<   r   r   r   ro   s       rB   
aexceptionzBoundLogger.aexception  sV      66*d#t+{0C0K \\^BzN$$T^^UD"EEEs   AA( A&!A(c                p   K   | j                  t        | j                  |      |||       d{    y7 w)zo
        Log using `log()`, but asynchronously in a separate thread.

        .. versionadded:: 23.1.0
        N)r   r   r   r   s        rB   alogzBoundLogger.alog  s-      $$WTXXu%=udBOOO   ,646)ra   r   rT   r   )rf   strrT   r   r   )rp   
str | Nonerq   r   rA   r   rT   r   )
r3   rS   rp   r   rq   r   rA   r   rT   r   )
r   r   rp   r   r   r   r   r   rT   r   )rT   r   )rT   rS   )rT   r   )rT   rR   )r3   rS   rT   None)F)rL   rR   rT   rU   )NN)rO   r   r3   rS   r   r   r   rS   r   r   rq   tuple[Any, ...]r   r   r   r   r   r   rT   logging.LogRecord)r   r   rT   r   )r   zlogging.HandlerrT   r   )r3   rS   rT   rR   )r   r   rT   r[   
r   zCallable[..., Any]rp   r   rq   r   rA   zdict[str, Any]rT   r   rp   r   rq   r   rA   r   rT   r   
r3   r   rp   r   rq   r   rA   r   rT   r   )/rV   rW   rX   rY   __annotations__r_   rd   rh   rj   rl   rt   rv   warnrx   r{   r~   r   r   rn   propertyrO   r3   r   r   r   r   r   rQ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__rb   s   @rB   r!   r!      s   . *%))BAD DBEE #'FF/2F:=F	F /3OO!+O;>OFIO	O !NN N 	N
 N 
N, ! ! " " # # & & % % % %% "'>>	)>"  

 
 	

 
 
 
 
 
 
 

&$&)**00-2 2 2 	2
 2 
2*BADBEEFPP!$P-0P8;P	PrC   r!   c                 ,    t        j                  | i |S )a/  
    Only calls `structlog.get_logger`, but has the correct type hints.

    .. warning::

       Does **not** check whether -- or ensure that -- you've configured
       *structlog* for standard library :mod:`logging`!

       See :doc:`standard-library` for details.

    .. versionadded:: 20.2.0
    )r   r)   )rq   initial_valuess     rB   r)   r)     s     t6~66rC   c                      e Zd ZU dZdZded<   ded<   dZeZddd	 	 	 	 	 	 	 	 	 dd	Z	e
dd
       ZddZddZddZddZ	 	 	 	 	 	 	 	 	 	 ddZddZddZddZddZddZddZddZddZddZy) AsyncBoundLoggera  
    Wraps a `BoundLogger` & exposes its logging methods as ``async`` versions.

    Instead of blocking the program, they are run asynchronously in a thread
    pool executor.

    This means more computational overhead per log call. But it also means that
    the processor chain (e.g. JSON serialization) and I/O won't block your
    whole application.

    Only available for Python 3.7 and later.

    .. versionadded:: 20.2.0
    .. versionchanged:: 20.2.0 fix _dispatch_to_sync contextvars usage
    .. deprecated:: 23.1.0
       Use the regular `BoundLogger` with its a-prefixed methods instead.
    .. versionchanged:: 23.3.0
        Callsite parameters are now also collected for async log methods.
    )_loopsync_blr!   r   r   _contextN)_sync_blr   c                   |r|| _         || _        y | j                  |||      | _         t        j                         | _        y )N)loggerr6   context)r   r   _bound_logger_factoryr   r   )rK   r   r6   r   r   r   s         rB   __init__zAsyncBoundLogger.__init__#  sH     #DLDJ11j' 2 
 --/
rC   c                .    | j                   j                  S r   )r   r   r   s    rB   r   zAsyncBoundLogger._context<  s    ||$$$rC   c           
     j    t        d di  | j                  j                  di || j                        S Nr9   )r   r6   r   r   r   )r   r   r_   r   rK   ra   s     rB   r_   zAsyncBoundLogger.bind@  s8     &T\\&&44**	
 		
rC   c           
     j    t        d di  | j                  j                  di || j                        S r  )r   r   rj   r   r  s     rB   rj   zAsyncBoundLogger.newL  s6    %T\\%%3
3**
 	
rC   c                d    t        d di  | j                  j                  | | j                        S r  )r   r   rd   r   rK   rf   s     rB   rd   zAsyncBoundLogger.unbindV  s3    (T\\(($/**
 	
rC   c                d    t        d di  | j                  j                  | | j                        S r  )r   r   rh   r   r  s     rB   rh   zAsyncBoundLogger.try_unbind`  s3    ,T\\,,d3**
 	
rC   c                  K   t        j                  t        j                         j                  j                        }t        j                         	 t        j                         j                  | j                  fd       d{    t        j                  |       y7 # t        j                  |       w xY ww)r   c                 2    j                   fd      S )Nc                      g i S r   r9   r   s   rB   r   zFAsyncBoundLogger._dispatch_to_sync.<locals>.<lambda>.<locals>.<lambda>z  r   rC   r   r   s   rB   r   z4AsyncBoundLogger._dispatch_to_sync.<locals>.<lambda>z  r   rC   N)r   r   r<   r   r   r   r   r   r   r   	_executorr   r   s    ```` @rB   r   z"AsyncBoundLogger._dispatch_to_syncj  s      ),,S]]_-C-C-J-JK	&&(	2**,<<A  
 !&&y1
 !&&y1s0   AC8B- B+B- C+B- -CCc                p   K   | j                  | j                  j                  |||       d {    y 7 wr   )r   r   rl   ro   s       rB   rl   zAsyncBoundLogger.debug  *     $$T\\%7%7bIIIr   c                p   K   | j                  | j                  j                  |||       d {    y 7 wr   )r   r   rt   ro   s       rB   rt   zAsyncBoundLogger.info  s*     $$T\\%6%6tRHHHr   c                p   K   | j                  | j                  j                  |||       d {    y 7 wr   r   r   rv   ro   s       rB   rv   zAsyncBoundLogger.warning  *     $$T\\%9%95$KKKr   c                p   K   | j                  | j                  j                  |||       d {    y 7 wr   r  ro   s       rB   r   zAsyncBoundLogger.warn  r  r   c                p   K   | j                  | j                  j                  |||       d {    y 7 wr   )r   r   rx   ro   s       rB   rx   zAsyncBoundLogger.error  r  r   c                p   K   | j                  | j                  j                  |||       d {    y 7 wr   r   r   r{   ro   s       rB   r{   zAsyncBoundLogger.critical  *     $$T\\%:%:E4LLLr   c                p   K   | j                  | j                  j                  |||       d {    y 7 wr   r  ro   s       rB   r~   zAsyncBoundLogger.fatal  r  r   c                   K   |j                  dd       }|%|j                  d      t        j                         }||d<   | j	                  | j
                  j                  |||       d {    y 7 w)Nr   r   )popr   r<   r   r   r   r   )rK   rp   rq   rA   eis        rB   r   zAsyncBoundLogger.exception  sc      VVJ%:"&&-5B:$$T\\%;%;UD"MMMs   A*A4,A2-A4c                   K   | j                  t        | j                  j                  |      |||       d {    y 7 wr   )r   r   r   r   r   s        rB   r   zAsyncBoundLogger.log  s8     $$DLL$$e,eT2
 	
 	
s   6A >A )
r   r[   r6   zIterable[Processor]r   r   r   r   r   r   )rT   r   )ra   r   rT   r   )rf   r   rT   r   r   r   r   )rV   rW   rX   rY   	__slots__r   r  r!   r   r  r   r   r_   rj   rd   rh   r   rl   rt   rv   r   rx   r{   r~   r   r   r9   rC   rB   r   r     s    ( %I  I' 00 (0 	0 0 02 % %




2 2 2 	2
 2 
2*JILLJMM	N
rC   r   c                  "    e Zd ZdZdddZddZy)r#   a  
    Build a standard library logger when an *instance* is called.

    Sets a custom logger using :func:`logging.setLoggerClass` so variables in
    log format are expanded properly.

    >>> from structlog import configure
    >>> from structlog.stdlib import LoggerFactory
    >>> configure(logger_factory=LoggerFactory())

    Args:
        ignore_frame_names:
            When guessing the name of a logger, skip frames whose names *start*
            with one of these.  For example, in pyramid applications you'll
            want to set it to ``["venusian", "pyramid.config"]``. This argument
            is called *additional_ignores* in other APIs throughout
            *structlog*.
    Nc                D    || _         t        j                  t               y r   )_ignorer:   setLoggerClassrE   )rK   ignore_frame_namess     rB   r  zLoggerFactory.__init__  s    )56rC   c                    |rt        j                  |d         S t        | j                        \  }}t        j                  |      S )aM  
        Deduce the caller's module name and create a stdlib logger.

        If an optional argument is passed, it will be used as the logger name
        instead of guesswork.  This optional argument would be passed from the
        :func:`structlog.get_logger` call.  For example
        ``structlog.get_logger("foo")`` would cause this method to be called
        with ``"foo"`` as its first positional argument.

        .. versionchanged:: 0.4.0
            Added support for optional positional arguments.  Using the first
            one for naming the constructed logger.
        r   )r:   	getLoggerr   r!  )rK   rq   _rO   s       rB   __call__zLoggerFactory.__call__  sA     $$T!W-- 1>4  &&rC   r   )r#  zlist[str] | None)rq   r   rT   r[   rV   rW   rX   rY   r  r'  r9   rC   rB   r#   r#     s    &7'rC   r#   c                  2    e Zd ZdZdddZ	 	 	 	 	 	 	 	 ddZy)r$   aN  
    Apply stdlib-like string formatting to the ``event`` key.

    If the ``positional_args`` key in the event dict is set, it must
    contain a tuple that is used for formatting (using the ``%s`` string
    formatting operator) of the value from the ``event`` key.  This works
    in the same way as the stdlib handles arguments to the various log
    methods: if the tuple contains only a single `dict` argument it is
    used for keyword placeholders in the ``event`` string, otherwise it
    will be used for positional placeholders.

    ``positional_args`` is populated by `structlog.stdlib.BoundLogger` or
    can be set manually.

    The *remove_positional_args* flag can be set to `False` to keep the
    ``positional_args`` key in the event dict; by default it will be
    removed from the event dict after formatting a message.
    c                    || _         y r   )remove_positional_args)rK   r+  s     rB   r  z%PositionalArgumentsFormatter.__init__  s
    &<#rC   c                    |j                  d      }|r8t        |      dk(  rt        |d   t              r
|d   r|d   }|dxx   |z  cc<   | j                  r||d= |S )Nr   r   r   rp   )r   len
isinstancedictr+  )rK   r&  __
event_dictrq   s        rB   r'  z%PositionalArgumentsFormatter.__call__  sl     ~~/0 4yA~*T!Wd";QAww4'&&4+;,-rC   N)T)r+  rR   rT   r   r&  r    r0  r   r1  r   rT   r   r(  r9   rC   rB   r$   r$     s1    &=$'5>	rC   r$   c                B    | j                  t        |         r|S t        )aA  
    Check whether logging is configured to accept messages from this log level.

    Should be the first processor if stdlib's filtering by level is used so
    possibly expensive processors like exception formatters are avoided in the
    first place.

    >>> import logging
    >>> from structlog.stdlib import filter_by_level
    >>> logging.basicConfig(level=logging.WARN)
    >>> logger = logging.getLogger()
    >>> filter_by_level(logger, 'warn', {})
    {}
    >>> filter_by_level(logger, 'debug', {})
    Traceback (most recent call last):
    ...
    DropEvent
    )r   r   r   r   r   r1  s      rB   r(   r(     s"    * =56
OrC   c                    t         |   |d<   |S )a  
    Add the log level number to the event dict.

    Log level numbers map to the log level names. The Python stdlib uses them
    for filtering logic. This adds the same numbers so users can leverage
    similar filtering. Compare::

       level in ("warning", "error", "critical")
       level_number >= 30

    The mapping of names to numbers is in
    ``structlog.stdlib._log_levels._NAME_TO_LEVEL``.

    .. versionadded:: 18.2.0
    level_number)r   r4  s      rB   r&   r&     s    $ "/{!;J~rC   c                l    |j                  d      }|| j                  |d<   |S |j                  |d<   |S )z0
    Add the logger name to the event dict.
    _recordr   )r   rO   )r   r   r1  r   s       rB   r'   r'   3  sC     ^^I&F~%{{
8   &{{
8rC   rO   pathnamer   r9   c                  v    e Zd ZdZdZdd	dZ	 	 	 	 	 	 	 	 d
dZe	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 dd       Z	y)r"   a  
    Add extra attributes of `logging.LogRecord` objects to the event
    dictionary.

    This processor can be used for adding data passed in the ``extra``
    parameter of the `logging` module's log methods to the event dictionary.

    Args:
        allow:
            An optional collection of attributes that, if present in
            `logging.LogRecord` objects, will be copied to event dictionaries.

            If ``allow`` is None all attributes of `logging.LogRecord` objects
            that do not exist on a standard `logging.LogRecord` object will be
            copied to event dictionaries.

    .. versionadded:: 21.5.0
    )_copierNc                ~    |  |(t        j                  | j                  g |      | _        y | j                  | _        y r   )	functoolsr   _copy_allowedr;  	_copy_all)rK   allows     rB   r  zExtraAdder.__init__\  s6     %,,T-?-?5JDL>>DLrC   c                P    |j                  d      }|| j                  ||       |S )Nr8  )r   r;  )rK   r   rO   r1  r   s        rB   r'  zExtraAdder.__call__f  s,     ,6>>)+DLLV,rC   c                d    |j                   j                         D ]  \  }}|t        vs|||<    y r   )__dict__items_LOG_RECORD_KEYS)clsr1  r   keyvalues        rB   r?  zExtraAdder._copy_alln  s6     !////1 	(JC**"'
3	(rC   c                T    |D ]#  }||j                   v s|j                   |   ||<   % y r   )rC  )rF  r@  r1  r   rG  s        rB   r>  zExtraAdder._copy_allowedv  s1      	7Cfoo%"(//#"6
3	7rC   r   )r@  zCollection[str] | NonerT   r   )r   r[   rO   r   r1  r   rT   r   )r1  r   r   r   rT   r   )r@  zCollection[str]r1  r   r   r   rT   r   )
rV   rW   rX   rY   r  r  r'  classmethodr?  r>  r9   rC   rB   r"   r"   F  s    & I*$,/=F	 ("(,=(	( ( 77 7 "	7
 
7 7rC   r"   )r   rL   rM   c                    |j                  d      g|j                  dd      }t        D ci c]  }||v r||j                  |       }}|r||d<   ||fS c c}w )a-  
    Render ``event_dict`` into positional and keyword arguments for
    `logging.Logger` logging methods.
    See `logging.Logger.debug` method for keyword arguments reference.

    The ``event`` field is passed in the first positional argument, positional
    arguments from ``positional_args`` field are passed in subsequent positional
    arguments, keyword arguments are extracted from the *event_dict* and the
    rest of the *event_dict* is added as ``extra``.

    This allows you to defer formatting to `logging`.

    .. versionadded:: 25.1.0
    rp   r   r9   r   r  LOG_KWARG_NAMES)r&  r0  r1  rq   
kwarg_namekwargss         rB   r+   r+     sx    " NN7#Ljnn5F&KLD *# 	JNN:..F 
 $w<s   Ac                    |j                  d      |dt        D ci c]  }||v r||j                  |       c}S c c}w )a  
    Render ``event_dict`` into keyword arguments for `logging.Logger` logging
    methods.
    See `logging.Logger.debug` method for keyword arguments reference.

    The ``event`` field is translated into ``msg``, keyword arguments are
    extracted from the *event_dict* and the rest of the *event_dict* is added as
    ``extra``.

    This allows you to defer formatting to `logging`.

    .. versionadded:: 17.1.0
    .. versionchanged:: 22.1.0
       ``exc_info``, ``stack_info``, and ``stacklevel`` are passed as proper
       kwargs and not put into ``extra``.
    .. versionchanged:: 24.2.0
       ``stackLevel`` corrected to ``stacklevel``.
    rp   )r   r   rL  )r&  r0  r1  rA   s       rB   r,   r,     sU    , ~~g&
 &
Z 
r""
 
s   =c                       e Zd ZdZ	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZd fdZe	 	 	 	 	 	 	 	 d	d       Ze	 	 	 	 	 	 	 	 d
d       Z xZ	S )r%   a  
    Call *structlog* processors on `logging.LogRecord`\s.

    This is an implementation of a `logging.Formatter` that can be used to
    format log entries from both *structlog* and `logging`.

    Its static method `wrap_for_formatter` must be the final processor in
    *structlog*'s processor chain.

    Please refer to :ref:`processor-formatter` for examples.

    Args:
        foreign_pre_chain:
            If not `None`, it is used as a processor chain that is applied to
            **non**-*structlog* log entries before the event dictionary is
            passed to *processors*. (default: `None`)

        processors:
            A chain of *structlog* processors that is used to process **all**
            log entries. The last one must render to a `str` which then gets
            passed on to `logging` for output.

            Compared to *structlog*'s regular processor chains, there's a few
            differences:

            - The event dictionary contains two additional keys:

              #. ``_record``: a `logging.LogRecord` that either was created
                  using `logging` APIs, **or** is a wrapped *structlog* log
                  entry created by `wrap_for_formatter`.

              #. ``_from_structlog``: a `bool` that indicates whether or not
                 ``_record`` was created by a *structlog* logger.

              Since you most likely don't want ``_record`` and
              ``_from_structlog`` in your log files,  we've added the static
              method `remove_processors_meta` to ``ProcessorFormatter`` that
              you can add just before your renderer.

            - Since this is a `logging` *formatter*, raising
              `structlog.DropEvent` will crash your application.

        keep_exc_info:
            ``exc_info`` on `logging.LogRecord`\ s is added to the
            ``event_dict`` and removed afterwards. Set this to ``True`` to keep
            it on the `logging.LogRecord`. (default: False)

        keep_stack_info:
            Same as *keep_exc_info* except for ``stack_info``. (default: False)

        logger:
            Logger which we want to push through the *structlog* processor
            chain. This parameter is necessary for some of the processors like
            `filter_by_level`. (default: None)

        pass_foreign_args:
            If True, pass a foreign log record's ``args`` attribute to the
            ``event_dict`` under ``positional_args`` key. (default: False)

        processor:
            A single *structlog* processor used for rendering the event
            dictionary before passing it off to `logging`. Must return a `str`.
            The event dictionary does **not** contain ``_record`` and
            ``_from_structlog``.

            This parameter exists for historic reasons. Please use *processors*
            instead.

        use_get_message:
            If True, use ``record.getMessage`` to get a fully rendered log
            message, otherwise use ``str(record.msg)``. (default: True)

    Raises:
        TypeError: If both or neither *processor* and *processors* are passed.

    .. versionadded:: 17.1.0
    .. versionadded:: 17.2.0 *keep_exc_info* and *keep_stack_info*
    .. versionadded:: 19.2.0 *logger*
    .. versionadded:: 19.2.0 *pass_foreign_args*
    .. versionadded:: 21.3.0 *processors*
    .. deprecated:: 21.3.0
       *processor* (singular) in favor of *processors* (plural). Removal is not
       planned.
    .. versionadded:: 23.3.0 *use_get_message*
    c	                    |
j                  dd      }t        |   |	d|i|
 |r|rd}t        |      |  || j                  |f| _        n|r|| _        nd}t        |      || _        || _        || _        || _	        || _
        || _        y )Nfmtr0   zBThe `processor` and `processors` arguments are mutually exclusive.z2Either `processor` or `processors` must be passed.)r  r^   r  	TypeErrorremove_processors_metar6   foreign_pre_chainkeep_exc_infokeep_stack_infor   pass_foreign_argsuse_get_message)rK   	processorr6   rV  rW  rX  r   rY  rZ  rq   rO  rS  r   rb   s                rB   r  zProcessorFormatter.__init__  s     jj.$2C262  C.  #::IFDO(DOFCC. !2*.!2.rC   c           	        t        j                  |j                        }t        |dt              }t        |dd      }|t        urw|dk7  rr| j
                  | j
                  }t        t        |j                        }t        t        t        t        f   |j                        j                         }||d<   d|d<   n| j
                  }|j                  j                         }| j                  r|j!                         nt        |j                        |dd	}| j"                  r|j$                  |d
<   d|_        |j&                  r|j&                  |d<   |j(                  r|j(                  |d<   | j*                  xs dD ]  }t        t,         ||||            } | j.                  sd|_        d|_        | j2                  sd|_        | j4                  D ]  } |||t        t,        |            } t7        |t              sIt9        j:                  d| j4                  d    dt=        |       dt>        d       t        t        |      }||_        t@        |   |      S )z
        Extract *structlog*'s `event_dict` from ``record.msg`` and format it.

        *record* has been patched by `wrap_for_formatter` first though, so the
         type isn't quite right.
        r\   _name__structlog_sentinel__Nr8  T_from_structlogF)rp   r8  r_  r   r9   r   rL   zNThe last processor in ProcessorFormatter.processors must return a string, but r5   z returned a z	 instead.r   )categoryrM   )"r:   makeLogRecordrC  getattr	_SENTINELr   r   r   r]  r   r   r   copy	levelnamelowerrZ  
getMessagerY  rq   r   rL   rV  r   rW  exc_textrX  r6   r.  warningsr   typeRuntimeWarningr^   r1   )rK   r   r   	meth_nameedprocprb   s          rB   r1   zProcessorFormatter.formatA  s.    &&v7I6FG-EF	 "y4L'L{{&S&,,/I
 d38nfjj1668B"ByM$(B ![[F((..0I ++ %%'VZZ!#(B %%(.$%FK !':  #)#4#4<  ..4" B)T&)R%@AB !!"FO"FO## $F 	;A69d9b&9:B	; "c"MM((,(;'<L8*I' ( c2B
w~f%%rC   c                    |fd| |difS )aH  
        Wrap *logger*, *name*, and *event_dict*.

        The result is later unpacked by `ProcessorFormatter` when formatting
        log entries.

        Use this static method as the renderer (in other words, final
        processor) if you want to use `ProcessorFormatter` in your `logging`
        configuration.
        r   )r\   r]  r9   )r   rO   r1  s      rB   wrap_for_formatterz%ProcessorFormatter.wrap_for_formatter  s     }wFT(JKKKrC   c                    |d= |d= |S )z
        Remove ``_record`` and ``_from_structlog`` from *event_dict*.

        These keys are added to the event dictionary, before
        `ProcessorFormatter`'s *processors* are run.

        .. versionadded:: 21.3.0
        r8  r_  r9   )r&  r0  r1  s      rB   rU  z)ProcessorFormatter.remove_processors_meta  s     y!()rC   )Nr9   NFFNFT)r[  zProcessor | Noner6   Sequence[Processor] | NonerV  rs  rW  rR   rX  rR   r   zlogging.Logger | NonerY  rR   rZ  rR   rq   r   rO  r   rT   r   )r   r   rT   r   )r   r[   rO   r   r1  r   rT   z2tuple[tuple[EventDict], dict[str, dict[str, Any]]]r2  )
rV   rW   rX   rY   r  r1   staticmethodrq  rU  r   r   s   @rB   r%   r%     s   Tp '+138<# %(,"' $%/#%/ /%/ 6	%/
 %/ %/ &%/  %/ %/ %/ %/ 
%/NP&d LL&)L7@L	;L L !/8	 rC   r%   )r-   z
int | NonerT   r   )rq   r   r   r   rT   r!   )r   r[   r   r   r1  r   rT   r   )r&  r[   r0  r   r1  r   rT   z&tuple[tuple[Any, ...], dict[str, Any]])r&  r[   r0  r   r1  r   rT   r   )ErY   
__future__r   r   r   r=  r:   r<   ri  r   typingr   r   r   r   r	   r
   r   version_infor   typing_extensions r   _baser   _framesr   r   _log_levelsr   r   r   r   r   
exceptionsr   r6   r   r   r   r   r   r   r    __all__NOTSETr*   objectrc  LoggerrE   r!   r)   r   r#   r$   r(   r&   r'   	LogRecordrC  rf   rE  r"   rM  r+   r,   	Formatterr%   r9   rC   rB   <module>r     s  
 #     
   L L L w&  " B D D @ ! ) " 29 .b H	IW^^ I,cP/ cPL7 a
 a
H-' -'`) )X),:C6),:C.),:C %7$$
Az1eR
(446 
97 97x ;,5+<,5@o** orC   