U
    
W[                     @   sV   d Z edZddlmZ ddlmZ dZejZ	eG dd dZ
dee	dfd	d
ZdS )zo
Classes and utility functions for integrating Twisted and syslog.

You probably want to call L{startLogging}.
syslog    )log)	_oldStylec                   @   s2   e Zd ZdZejZejZeefddZdd Z	dS )SyslogObserveraU  
    A log observer for logging to syslog.

    See L{twisted.python.log} for context.

    This logObserver will automatically use LOG_ALERT priority for logged
    failures (such as from C{log.err()}), but you can use any priority and
    facility by setting the 'C{syslogPriority}' and 'C{syslogFacility}' keys in
    the event dict.
    c                 C   s   |  ||| dS )a  
        @type prefix: C{str}
        @param prefix: The syslog prefix to use.

        @type options: C{int}
        @param options: A bitvector represented as an integer of the syslog
            options to use.

        @type facility: C{int}
        @param facility: An indication to the syslog daemon of what sort of
            program this is (essentially, an additional arbitrary metadata
            classification for messages sent to syslog by this observer).
        N)openlog)selfprefixoptionsfacility r   7/usr/lib/python3/dist-packages/twisted/python/syslog.py__init__%   s    zSyslogObserver.__init__c                 C   s   t |}|dkrdS tj}d}|d r.tj}d|krBt|d }d|krVt|d }|d}|dd dgkr||  q`d	}|D ]2}|rd
}nd| }| ||B d|d |f  qdS )a  
        Send a message event to the I{syslog}.

        @param eventDict: The event to send.  If it has no C{'message'} key, it
            will be ignored.  Otherwise, if it has C{'syslogPriority'} and/or
            C{'syslogFacility'} keys, these will be used as the syslog priority
            and facility.  If it has no C{'syslogPriority'} key but a true
            value for the C{'isError'} key, the B{LOG_ALERT} priority will be
            used; if it has a false value for C{'isError'}, B{LOG_INFO} will be
            used.  If the C{'message'} key is multiline, each line will be sent
            to the syslog separately.
        Nr   ZisErrorZsyslogPriorityZsyslogFacility
 TF	z[%s] %ssystem)r   ZtextFromEventDictr   ZLOG_INFOZ	LOG_ALERTintsplitpop)r   Z	eventDicttextZpriorityr
   linesZ	firstLineliner   r   r   emit7   s,    



zSyslogObserver.emitN)
__name__
__module____qualname____doc__r   r   DEFAULT_OPTIONSDEFAULT_FACILITYr   r   r   r   r   r   r      s   

r   ZTwisted   c                 C   s    t | ||}tj|j|d dS )a  
    Send all Twisted logging output to syslog from now on.

    The prefix, options and facility arguments are passed to
    C{syslog.openlog()}, see the Python syslog documentation for details. For
    other parameters, see L{twisted.python.log.startLoggingWithObserver}.
    )	setStdoutN)r   r   ZstartLoggingWithObserverr   )r   r	   r
   r!   Zobsr   r   r   startLoggingc   s    	r"   N)r   
__import__r   Ztwisted.pythonr   Ztwisted.python._oldstyler   r   ZLOG_USERr   r   r"   r   r   r   r   <module>   s   L 