
    \d&                         d Z ddlmZ ddlmZmZ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  G d	 d
          Z e            Zd ZdS )z
Logger class.
    )time)AnyOptionalcast)currentframe)Failure   )ILogObserverLogTrace)InvalidLogLevelErrorLogLevelc                      e Zd ZdZedefd            Z	 	 	 ddee         dee         ded         ddfd	Z	dd
edee
         dd fdZdefdZ	 ddedee         deddfdZdej        fdedee         dededdf
dZddee         deddfdZddee         deddfdZddee         deddfdZddee         deddfdZddee         deddfdZdS )Loggera~  
    A L{Logger} emits log messages to an observer.  You should instantiate it
    as a class or module attribute, as documented in L{this module's
    documentation <twisted.logger>}.

    @ivar namespace: the namespace for this logger
    @ivar source: The object which is emitting events via this logger
    @ivar observer: The observer that this logger will send events to.
    returnc                      	 t          t          t          d          j        d                   S # t          $ r Y dS w xY w)z
        Derive a namespace from the module containing the caller's caller.

        @return: the fully qualified python name of a module.
           __name__z	<unknown>)r   strr   	f_globalsKeyError     6lib/python3.11/site-packages/twisted/logger/_logger.py_namespaceFromCallingContextz#Logger._namespaceFromCallingContext   sG    	\!__6zBCCC 	 	 	;;	s   ,/ 
==N	namespacesourceobserverr
   c                 ~    ||                                  }|| _        || _        |ddlm} || _        dS || _        dS )a3  
        @param namespace: The namespace for this logger.  Uses a dotted
            notation, as used by python modules.  If not L{None}, then the name
            of the module of the caller is used.
        @param source: The object which is emitting events via this
            logger; this is automatically set on instances of a class
            if this L{Logger} is an attribute of that class.
        @param observer: The observer that this logger will send events to.
            If L{None}, use the L{global log publisher <globalLogPublisher>}.
        Nr	   )globalLogPublisher)r   r   r   _globalr   r   )selfr   r   r   r   s        r   __init__zLogger.__init__)   sW      99;;I"333333*<DMMM$DMMMr   instanceownerc                     |J ||}n|}|                      d                    |j        |j        g          || j                  S )a  
        When used as a descriptor, i.e.::

            # File: athing.py
            class Something:
                log = Logger()
                def hello(self):
                    self.log.info("Hello")

        a L{Logger}'s namespace will be set to the name of the class it is
        declared on.  In the above example, the namespace would be
        C{athing.Something}.

        Additionally, its source will be set to the actual object referring to
        the L{Logger}.  In the above example, C{Something.log.source} would be
        C{Something}, and C{Something().log.source} would be an instance of
        C{Something}.
        N.)r   )	__class__join
__module__r   r   )r!   r#   r$   r   s       r   __get__zLogger.__get__F   s^    &    FFF~~HHe&788]  
 
 	
r   c                 2    d| j         j         d| j        dS )N< >)r'   r   r   )r!   s    r   __repr__zLogger.__repr__f   s"    @4>*@@T^@@@@r   levelformatkwargsc           	         |t          j                    vr5|                     dt          t	          |                    ||            dS |}|                    | || j        | j        |t                                 d|v r5t          t          |d                                       | | j        f           |                     |           dS )a  
        Emit a log event to all log observers at the given level.

        @param level: a L{LogLevel}
        @param format: a message format using new-style (PEP 3101)
            formatting.  The logging event (which is a L{dict}) is
            used to render this format string.
        @param kwargs: additional key/value pairs to include in the event.
            Note that values which are later mutated may result in
            non-deterministic behavior from observers that schedule work for
            later execution.
        z:Got invalid log level {invalidLevel!r} in {logger}.emit().)invalidLevelloggerN)
log_logger	log_levellog_namespace
log_source
log_formatlog_time	log_trace)r   iterconstantsfailurer   r   updater   r   r   r   r   appendr   )r!   r0   r1   r2   events        r   emitzLogger.emiti   s     .0000LLL,U3344"	     F.{VV 	 	
 	
 	
 %5-..55tT]6KLLLer   r>   c                 H    |t                      } | j        ||fd|i| dS )a2  
        Log a failure and emit a traceback.

        For example::

            try:
                frob(knob)
            except Exception:
                log.failure("While frobbing {knob}", knob=knob)

        or::

            d = deferredFrob(knob)
            d.addErrback(lambda f: log.failure("While frobbing {knob}",
                                               f, knob=knob))

        This method is generally meant to capture unexpected exceptions in
        code; an exception that is caught and handled somehow should be logged,
        if appropriate, via L{Logger.error} instead.  If some unknown exception
        occurs and your code doesn't know how to handle it, as in the above
        example, then this method provides a means to describe the failure in
        nerd-speak.  This is done at L{LogLevel.critical} by default, since no
        corrective guidance can be offered to an user/administrator, and the
        impact of the condition is unknown.

        @param format: a message format using new-style (PEP 3101) formatting.
            The logging event (which is a L{dict}) is used to render this
            format string.
        @param failure: a L{Failure} to log.  If L{None}, a L{Failure} is
            created from the exception in flight.
        @param level: a L{LogLevel} to use.
        @param kwargs: additional key/value pairs to include in the event.
            Note that values which are later mutated may result in
            non-deterministic behavior from observers that schedule work for
            later execution.
        Nlog_failure)r   rB   )r!   r1   r>   r0   r2   s        r   r>   zLogger.failure   s:    V ?iiG	%??W??????r   c                 8     | j         t          j        |fi | dS )a  
        Emit a log event at log level L{LogLevel.debug}.

        @param format: a message format using new-style (PEP 3101) formatting.
            The logging event (which is a L{dict}) is used to render this
            format string.

        @param kwargs: additional key/value pairs to include in the event.
            Note that values which are later mutated may result in
            non-deterministic behavior from observers that schedule work for
            later execution.
        N)rB   r   debugr!   r1   r2   s      r   rF   zLogger.debug   (     		(.&33F33333r   c                 8     | j         t          j        |fi | dS )a  
        Emit a log event at log level L{LogLevel.info}.

        @param format: a message format using new-style (PEP 3101) formatting.
            The logging event (which is a L{dict}) is used to render this
            format string.

        @param kwargs: additional key/value pairs to include in the event.
            Note that values which are later mutated may result in
            non-deterministic behavior from observers that schedule work for
            later execution.
        N)rB   r   inforG   s      r   rJ   zLogger.info   (     		(-22622222r   c                 8     | j         t          j        |fi | dS )a  
        Emit a log event at log level L{LogLevel.warn}.

        @param format: a message format using new-style (PEP 3101) formatting.
            The logging event (which is a L{dict}) is used to render this
            format string.

        @param kwargs: additional key/value pairs to include in the event.
            Note that values which are later mutated may result in
            non-deterministic behavior from observers that schedule work for
            later execution.
        N)rB   r   warnrG   s      r   rM   zLogger.warn   rK   r   c                 8     | j         t          j        |fi | dS )a  
        Emit a log event at log level L{LogLevel.error}.

        @param format: a message format using new-style (PEP 3101) formatting.
            The logging event (which is a L{dict}) is used to render this
            format string.

        @param kwargs: additional key/value pairs to include in the event.
            Note that values which are later mutated may result in
            non-deterministic behavior from observers that schedule work for
            later execution.
        N)rB   r   errorrG   s      r   rO   zLogger.error   rH   r   c                 8     | j         t          j        |fi | dS )a  
        Emit a log event at log level L{LogLevel.critical}.

        @param format: a message format using new-style (PEP 3101) formatting.
            The logging event (which is a L{dict}) is used to render this
            format string.

        @param kwargs: additional key/value pairs to include in the event.
            Note that values which are later mutated may result in
            non-deterministic behavior from observers that schedule work for
            later execution.
        N)rB   r   criticalrG   s      r   rQ   zLogger.critical   s)     		(#V66v66666r   )NNNN)r   r)   __qualname____doc__staticmethodr   r   r   objectr"   typer*   r/   r   rB   rQ   r   r>   rF   rJ   rM   rO   r   r   r   r   r      s         	# 	 	 	 \	 $(#'-1	% %C=%  % >*	%
 
% % % %:
 
 
x~ 
 
 
 
 
@A# A A A A 8<% %%'/}%GM%	% % % %T &*"+	.@ .@.@ '".@ 	.@
 .@ 
.@ .@ .@ .@`4 4HSM 4F 4t 4 4 4 43 38C= 36 3d 3 3 3 33 38C= 36 3d 3 3 3 34 4HSM 4F 4t 4 4 4 47 7x} 7v 7$ 7 7 7 7 7 7r   r   c                 B    t                               | | j                  S rR   )_logr*   r'   )objs    r   <lambda>r[     s    c3=99 r   N)rT   r   typingr   r   r   twisted.python.compatr   twisted.python.failurer   _interfacesr
   r   _levelsr   r   r   rY   
_loggerForr   r   r   <module>rb      s   
        & & & & & & & & & & . . . . . . * * * * * * / / / / / / / / 3 3 3 3 3 3 3 3w7 w7 w7 w7 w7 w7 w7 w7t vxx99


r   