o
    h5                  
   @  s  U d Z ddl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 ddlmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZmZmZ ddlmZmZmZmZ 	 eee eedddeej dddkoej dddkpeoej!duoe"ej!doej!# dgZ$de%d< eee e&Z'edZ(e Z)dZ*G dd dZ+e+ Z,	 d=ddZ-d>ddZ.d?d"d#Z/e/Z0	 					d@dAd0d1Z1					d@dBd5d6Z2					d@dBd7d8Z3dCd9d:Z4G d;d< d<Z5dS )DzJ
Global state department.  Don't reload this module or everything breaks.
    )annotationsN)AnyCallableIterableSequenceTypecast   )make_filtering_bound_logger)PrintLoggerFactory)merge_contextvars)ConsoleRenderer_has_colorsset_exc_info)StackInfoRendererTimeStamperadd_log_level)BindableLoggerContext	ProcessorWrappedLoggerz%Y-%m-%d %H:%M:%SF)fmtutcNO_COLOR FORCE_COLORisatty)colorszSequence[Processor]_BUILTIN_DEFAULT_PROCESSORSc                   @  sb   e Zd ZU dZdZded< edd Zded< eZ	ded	< e
Zd
ed< eZded< eZded< dS )_Configurationz
    Global defaults.
    Fboolis_configuredNzIterable[Processor]default_processorsztype[Context]default_context_classr   default_wrapper_classzCallable[..., WrappedLogger]logger_factorycache_logger_on_first_use)__name__
__module____qualname____doc__r!   __annotations__r   r"   _BUILTIN_DEFAULT_CONTEXT_CLASSr#   _BUILTIN_DEFAULT_WRAPPER_CLASSr$   _BUILTIN_DEFAULT_LOGGER_FACTORYr%   "_BUILTIN_CACHE_LOGGER_ON_FIRST_USEr&    r0   r0   G/var/www/html/ai/venv/lib/python3.10/site-packages/structlog/_config.pyr   9   s   
 
r   returnr    c                   C  s   t jS )z
    Return whether *structlog* has been configured.

    If `False`, *structlog* is running with builtin defaults.

    .. versionadded: 18.1.0
    )_CONFIGr!   r0   r0   r0   r1   r!   N   s   r!   dict[str, Any]c                   C  s   t jt jt jt jt jdS )z
    Get a dictionary with the current configuration.

    .. note::

       Changes to the returned dictionary do *not* affect *structlog*.

    .. versionadded: 18.1.0
    )
processorscontext_classwrapper_classr%   r&   )r3   r"   r#   r$   r%   r&   r0   r0   r0   r1   
get_configY   s   r8   argsr   initial_valuesc                  O  s   t dd| i|S )ar  
    Convenience function that returns a logger according to configuration.

    >>> from structlog import get_logger
    >>> log = get_logger(y=23)
    >>> log.info("hello", x=42)
    y=23 x=42 event='hello'

    Arguments:

        args:
            *Optional* positional arguments that are passed unmodified to the
            logger factory.  Therefore it depends on the factory what they
            mean.

        initial_values: Values that are used to pre-populate your contexts.

    Returns:

        A proxy that creates a correctly configured bound logger when
        necessary. The type of that bound logger depends on your configuration
        and is `structlog.BoundLogger` by default.

    See `configuration` for details.

    If you prefer CamelCase, there's an alias for your reading pleasure:
    `structlog.getLogger`.

    .. versionadded:: 0.4.0 *args*
    Nlogger_factory_argsN)wrap_logger)r9   r:   r0   r0   r1   
get_loggerl   s   r>   loggerWrappedLogger | Noner5   Iterable[Processor] | Noner7   type[BindableLogger] | Noner6   type[Context] | Noner&   bool | Noner;   Iterable[Any] | Nonec              	   K  s   t | ||||||dS )aJ  
    Create a new bound logger for an arbitrary *logger*.

    Default values for *processors*, *wrapper_class*, and *context_class* can
    be set using `configure`.

    If you set an attribute here, `configure` calls have *no* effect for the
    *respective* attribute.

    In other words: selective overwriting of the defaults while keeping some
    *is* possible.

    Arguments:

        initial_values: Values that are used to pre-populate your contexts.

        logger_factory_args:
            Values that are passed unmodified as ``*logger_factory_args`` to
            the logger factory if not `None`.

    Returns:

        A proxy that creates a correctly configured bound logger when
        necessary.

    See `configure` for the meaning of the rest of the arguments.

    .. versionadded:: 0.4.0 *logger_factory_args*
    )r7   r5   r6   r&   r:   r;   )BoundLoggerLazyProxy)r?   r5   r7   r6   r&   r;   r:   r0   r0   r1   r=      s   &r=   r%   #Callable[..., WrappedLogger] | NoneNonec                 C  sT   dt _| dur
| t _|dur|t _|dur|t _|dur|t _|dur(|t _dS dS )a   
    Configures the **global** defaults.

    They are used if `wrap_logger` or `get_logger` are called without
    arguments.

    Can be called several times, keeping an argument at `None` leaves it
    unchanged from the current setting.

    After calling for the first time, `is_configured` starts returning `True`.

    Use `reset_defaults` to undo your changes.

    Arguments:

        processors: The processor chain. See :doc:`processors` for details.

        wrapper_class:
            Class to use for wrapping loggers instead of
            `structlog.BoundLogger`.  See `standard-library`, :doc:`twisted`,
            and `custom-wrappers`.

        context_class:
            Class to be used for internal context keeping. The default is a
            `dict` and since dictionaries are ordered as of Python 3.6, there's
            few reasons to change this option.

        logger_factory:
            Factory to be called to create a new logger that shall be wrapped.

        cache_logger_on_first_use:
            `wrap_logger` doesn't return an actual wrapped logger but a proxy
            that assembles one when it's first used. If this option is set to
            `True`, this assembled logger is cached. See `performance`.

    .. versionadded:: 0.3.0 *cache_logger_on_first_use*
    TN)r3   r!   r"   r$   r#   r%   r&   r5   r7   r6   r%   r&   r0   r0   r1   	configure   s   ,
rJ   c                 C  s0   t jst| ||||d dS tjdtdd dS )z
    Configures if structlog isn't configured yet.

    It does *not* matter whether it was configured using `configure` or
    `configure_once` before.

    Raises:

        RuntimeWarning: if repeated configuration is attempted.
    rI   z!Repeated configuration attempted.   )
stacklevelN)r3   r!   rJ   warningswarnRuntimeWarningrI   r0   r0   r1   configure_once  s   

rP   c                   C  s0   dt _tdd t _tt _tt _tt _	t
t _dS )zu
    Resets global default values to builtin defaults.

    `is_configured` starts returning `False` afterwards.
    FN)r3   r!   r   r"   r-   r$   r,   r#   r.   r%   r/   r&   r0   r0   r0   r1   reset_defaults!  s   
rQ   c                   @  sx   e Zd ZdZ						d,d-ddZd.ddZd/ddZd0ddZd0dd Zd/d!d"Z	d1d$d%Z
d2d'd(Zd3d*d+ZdS )4rF   a  
    Instantiates a bound logger on first usage.

    Takes both configuration and instantiation parameters into account.

    The only points where a bound logger changes state are ``bind()``,
    ``unbind()``, and ``new()`` and that return the actual ``BoundLogger``.

    If and only if configuration says so, that actual bound logger is cached on
    first usage.

    .. versionchanged:: 0.4.0 Added support for *logger_factory_args*.
    Nr?   r@   r7   rB   r5   rA   r6   rC   r&   rD   r:   dict[str, Any] | Noner;   r   r2   rH   c                 C  s6   || _ || _|| _|| _|| _|pi | _|pd| _d S )Nr0   )_logger_wrapper_class_processors_context_class_cache_logger_on_first_use_initial_values_logger_factory_args)selfr?   r7   r5   r6   r&   r:   r;   r0   r0   r1   __init__>  s   

zBoundLoggerLazyProxy.__init__strc                 C  s6   d| j d| jd| jd| jd| jd| jdS )Nz<BoundLoggerLazyProxy(logger=z, wrapper_class=z, processors=z, context_class=z, initial_values=z, logger_factory_args=z)>)rS   rT   rU   rV   rX   rY   rZ   r0   r0   r1   __repr__P  s   
zBoundLoggerLazyProxy.__repr__
new_valuesr   c                   s   | j r
|  | j}nt| j}| j}|stj| j }| jdu r$tj}n| j}| j	p,tj
}||||d d
 fdd}| jd	u sJ| jdu rMtjd	u rM|| _|di |S )zN
        Assemble a new BoundLogger from arguments and configuration.
        N)r5   contextr_   r   r2   r   c                    s   | r
 j di | S  S )zU
            Use cached assembled logger to bind potentially new values.
            Nr0   )bind)r_   r?   r0   r1   finalized_bindr  s   z1BoundLoggerLazyProxy.bind.<locals>.finalized_bindTr_   r   r2   r   r0   )rV   rX   r3   r#   rS   r%   rY   rU   r"   rT   r$   rW   r&   ra   )rZ   r_   ctxrS   procsclsrc   r0   rb   r1   ra   Y  s&   

	

zBoundLoggerLazyProxy.bindkeysc                 G     |   j| S )zs
        Same as bind, except unbind *keys* first.

        In our case that could be only initial values.
        )ra   unbindrZ   rh   r0   r0   r1   rj     s   zBoundLoggerLazyProxy.unbindc                 G  ri   r<   )ra   
try_unbindrk   r0   r0   r1   rl     s   zBoundLoggerLazyProxy.try_unbindc                 K  s0   | j r
|     nt   | jdi |S )z+
        Clear context, then bind.
        Nr0   )rV   clearr3   r#   ra   )rZ   r_   r0   r0   r1   new  s   zBoundLoggerLazyProxy.newnamec                 C  s   |dkrt |  }t||S )zz
        If a logging method if called on a lazy proxy, we have to create an
        ephemeral BoundLogger first.
        __isabstractmethod__)AttributeErrorra   getattr)rZ   ro   blr0   r0   r1   __getattr__  s   
z BoundLoggerLazyProxy.__getattr__r4   c                 C  s   | j S )=
        Our __getattr__ magic makes this necessary.
        )__dict__r]   r0   r0   r1   __getstate__  s   z!BoundLoggerLazyProxy.__getstate__statec                 C  s"   |  D ]
\}}t| || qdS )ru   N)itemssetattr)rZ   rx   kvr0   r0   r1   __setstate__  s   z!BoundLoggerLazyProxy.__setstate__)NNNNNN)r?   r@   r7   rB   r5   rA   r6   rC   r&   rD   r:   rR   r;   r   r2   rH   )r2   r\   rd   )rh   r\   r2   r   )ro   r\   r2   r   r2   r4   )rx   r4   r2   rH   )r'   r(   r)   r*   r[   r^   ra   rj   rl   rn   rt   rw   r}   r0   r0   r0   r1   rF   /  s"    

	
*



rF   )r2   r    r~   )r9   r   r:   r   r2   r   )NNNNN)r?   r@   r5   rA   r7   rB   r6   rC   r&   rD   r;   rE   r:   r   r2   r   )r5   rA   r7   rB   r6   rC   r%   rG   r&   rD   r2   rH   )r2   rH   )6r*   
__future__r   ossysrM   typingr   r   r   r   r   r   _log_levelsr
   _outputr   contextvarsr   devr   r   r   r5   r   r   r   r   r   r   r   environgetstdouthasattrr   r   r+   dictr,   r-   r.   r/   r   r3   r!   r8   r>   	getLoggerr=   rJ   rP   rQ   rF   r0   r0   r0   r1   <module>   sz    




"
2;
