← Back
Editing: _observer.cpython-38.pyc
U W[ � @ s\ d Z ddlmZmZ ddlmZ ddlmZ dZG dd� de�Z ee �G d d � d e ��ZdS )z Basic log observers. � )� Interface�implementer)�Failure� )�LoggerzITemporarily disabling observer {observer} due to exception: {log_failure}c @ s e Zd ZdZdd� ZdS )�ILogObservera An observer which can handle log events. Unlike most interfaces within Twisted, an L{ILogObserver} I{must be thread-safe}. Log observers may be called indiscriminately from many different threads, as any thread may wish to log a message at any time. c C s dS )a� Log an event. @type event: C{dict} with (native) C{str} keys. @param event: A dictionary with arbitrary keys as defined by the application emitting logging events, as well as keys added by the logging system. The logging system reserves the right to set any key beginning with the prefix C{"log_"}; applications should not use any key so named. Currently, the following keys are used by the logging system in some way, if they are present (they are all optional): - C{"log_format"}: a PEP-3101-style format string which draws upon the keys in the event as its values, used to format the event for human consumption. - C{"log_flattened"}: a dictionary mapping keys derived from the names and format values used in the C{"log_format"} string to their values. This is used to preserve some structured information for use with L{twisted.logger.extractField}. - C{"log_trace"}: A L{list} designed to capture information about which L{LogPublisher}s have observed the event. - C{"log_level"}: a L{log level <twisted.logger.LogLevel>} constant, indicating the importance of and audience for this event. - C{"log_namespace"}: a namespace for the emitter of the event, given as a unicode string. - C{"log_system"}: a string indicating the network event or method call which resulted in the message being logged. N� )�eventr r �:/usr/lib/python3/dist-packages/twisted/logger/_observer.py�__call__ s zILogObserver.__call__N)�__name__� __module__�__qualname__�__doc__r r r r r r s r c @ s8 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� ZdS ) �LogPublisherz� I{ILogObserver} that fans out events to other observers. Keeps track of a set of L{ILogObserver} objects and forwards events to each. c G s t |�| _t| d�| _d S )N��observer)�list� _observersr �log)�selfZ observersr r r �__init__O s zLogPublisher.__init__c C s0 t |�std�|���|| jkr,| j�|� dS )zq Registers an observer with this publisher. @param observer: An L{ILogObserver} to add. zObserver is not callable: {0!r}N)�callable� TypeError�formatr �append�r r r r r �addObserverT s zLogPublisher.addObserverc C s* z| j �|� W n tk r$ Y nX dS )zv Unregisters an observer with this publisher. @param observer: An L{ILogObserver} to remove. N)r �remove� ValueErrorr r r r �removeObserver` s zLogPublisher.removeObserverc s� d� kr� �fdd�}nd}g }�j D ]F}|dk r:||� z|� � W q& tk rj |�|t� f� Y q&X q&|D ]"\}}��|�}|jt||d� qrdS )z8 Forward events to contained observers. � log_tracec s � d � �| f� dS )z� Add tracing information for an observer. @param observer: an observer being forwarded to @type observer: L{ILogObserver} r! N)r r �r r r r �traceq s z$LogPublisher.__call__.<locals>.traceN)�failurer )r � Exceptionr r �_errorLoggerForObserverr$ �OBSERVER_DISABLED)r r r# ZbrokenObserversr ZbrokenObserverr$ ZerrorLoggerr r"