U
    
W[	                     @   sx   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ eeG d	d
 d
eZe
fddZdS )z
File log observer.
    )implementer)ioTypeunicode   )ILogObserver
formatTime)timeFormatRFC3339formatEventAsClassicLogTextc                   @   s    e Zd ZdZdd Zdd ZdS )FileLogObserverz9
    Log observer that writes to a file-like object.
    c                 C   s*   t |tk	rd| _nd| _|| _|| _dS )a  
        @param outFile: A file-like object.  Ideally one should be passed which
            accepts L{unicode} data.  Otherwise, UTF-8 L{bytes} will be used.
        @type outFile: L{io.IOBase}

        @param formatEvent: A callable that formats an event.
        @type formatEvent: L{callable} that takes an C{event} argument and
            returns a formatted event as L{unicode}.
        zutf-8N)r   r   	_encoding_outFileformatEvent)selfoutFiler    r   6/usr/lib/python3/dist-packages/twisted/logger/_file.py__init__   s
    
zFileLogObserver.__init__c                 C   sJ   |  |}|dkrd}| jdk	r,|| j}|rF| j| | j  dS )zd
        Write event to file.

        @param event: An event.
        @type event: L{dict}
        N )r   r   encoder   writeflush)r   eventtextr   r   r   __call__+   s    

zFileLogObserver.__call__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   c                    s    fdd}t | |S )aa  
    Create a L{FileLogObserver} that emits text to a specified (writable)
    file-like object.

    @param outFile: A file-like object.  Ideally one should be passed which
        accepts L{unicode} data.  Otherwise, UTF-8 L{bytes} will be used.
    @type outFile: L{io.IOBase}

    @param timeFormat: The format to use when adding timestamp prefixes to
        logged events.  If L{None}, or for events with no C{"log_timestamp"}
        key, the default timestamp prefix of C{u"-"} is used.
    @type timeFormat: L{unicode} or L{None}

    @return: A file log observer.
    @rtype: L{FileLogObserver}
    c                    s   t |  fdddS )Nc                    s
   t |  S )Nr   )e
timeFormatr   r   <lambda>S       z:textFileLogObserver.<locals>.formatEvent.<locals>.<lambda>r   r
   )r   r!   r   r   r   Q   s     
z(textFileLogObserver.<locals>.formatEvent)r   )r   r"   r   r   r!   r   textFileLogObserver@   s    r%   N)r   Zzope.interfacer   Ztwisted.python.compatr   r   Z	_observerr   Z_formatr   r	   r   objectr   r%   r   r   r   r   <module>   s   ,