Ë
    ojþ&  ã                   óˆ   — 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y)z
Logger class.
é    )Útime)ÚAnyÚOptionalÚcast)Úcurrentframe)ÚFailureé   )ÚILogObserverÚLogTrace)ÚInvalidLogLevelErrorÚLogLevelc                   ój  — 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y)Ú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                  ón   — 	 t        t        t        d«      j                  d   «      S # t        $ r Y y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© ó    ú8/usr/lib/python3/dist-packages/twisted/logger/_logger.pyÚ_namespaceFromCallingContextz#Logger._namespaceFromCallingContext   s5   € ð	Üœœ\¨!›_×6Ñ6°zÑBÓCÐCøÜò 	Ùð	ús   ‚%( ¨	4³4NÚ	namespaceÚsourceÚobserverr
   c                 ór   — |€| j                  «       }|| _        || _        |€ddlm} || _        y|| _        y)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__)   s=   € ð  ÐØ×9Ñ9Ó;ˆIà"ˆŒØˆŒàÐÝ3à*<ˆD�Mà$ˆD�Mr   ÚinstanceÚownerc                 óž   — |€J ‚|€|}n|}| j                  dj                  |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}.
        ú.)r   )Ú	__class__ÚjoinÚ
__module__r   r   )r!   r#   r$   r   s       r   Ú__get__zLogger.__get__F   s[   € ð& Ð Ð Ð àÐØ‰FàˆFà�~‰~Ø�H‰H�e×&Ñ&¨¯©Ð7Ó8ØØ—]‘]ð ó 
ð 	
r   c                 óP   — d| j                   j                  › d| j                  ›d�S )Nú<ú ú>)r'   r   r   )r!   s    r   Ú__repr__zLogger.__repr__f   s'   € Ø�4—>‘>×*Ñ*Ð+¨1¨T¯^©^Ð,>¸aÐ@Ð@r   ÚlevelÚformatÚkwargsc           	      óp  — |t        j                  «       vr(| j                  dt        t	        |«      «      || ¬«       y|}|j                  | || j                  | j                  |t        «       ¬«       d|v r.t        t        |d   «      j                  | | j                  f«       | j                  |«       y)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Ø�L‰LØLÜÔ,¨UÓ3Ó4Ø"Øð	 ô ð àˆØ�‰ØØØŸ.™.Ø—{‘{ØÜ“Vð 	ô 	
ð ˜%ÑÜ”˜5 Ñ-Ó.×5Ñ5°t¸T¿]¹]Ð6KÔLà�‰�eÕr   r>   c                 óH   — |€
t        «       } | j                  ||fd|i|¤Ž y)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 ˆ?Ü“iˆGàˆ�	‰	�%˜Ñ?¨WÐ?¸Ó?r   c                 óH   —  | j                   t        j                  |fi |¤Ž y)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¨FÓ3r   c                 óH   —  | j                   t        j                  |fi |¤Ž y)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¨6Ó2r   c                 óH   —  | j                   t        j                  |fi |¤Ž y)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                 óH   —  | j                   t        j                  |fi |¤Ž y)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                 óH   —  | j                   t        j                  |fi |¤Ž y)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¨vÓ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ð 8<ñ%Øð%Ø'/°¡}ð%ØGMð%à	ó%ðT &*Ø"×+Ñ+ñ	.@àð.@ð ˜'Ñ"ð.@ð ð	.@ð
 ð.@ð 
ó.@ñ`4˜H S™Mð 4¸Fð 4Àtó 4ñ3˜8 C™=ð 3¸6ð 3Àdó 3ñ3˜8 C™=ð 3¸6ð 3Àdó 3ñ4˜H S™Mð 4¸Fð 4Àtó 4ñ7˜x¨™}ð 7¸vð 7È$ô 7r   r   c                 óB   — t         j                  | | j                  «      S rR   )Ú_logr*   r'   )Úobjs    r   ú<lambda>r[     s   € œŸ™ c¨3¯=©=Ó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÷w7ñ w7ñt ƒx€Ù9�
r   