
    #&a                     R    d dl mZ d dlZd dlZd dlZ G d dej
                        Zy)    Nc                        e Zd ZdZdZdZeZdZdZdZ	dZ
dZdZd	Zd
ej                  fej                   j"                  d	d	df fd	Zd Z xZS )WebsockifySysLogHandlerzb
    A handler class that sends proper Syslog-formatted messages,
    as defined by RFC 5424.
    z<{pri}>{ident}[{pid}]: z2<{pri}>1 {timestamp} {hostname} {ident} {pid} - - Fz%Y-%m-%dT%H:%M:%SZ      
N	localhostc                 j    || _         |rd| _        | j                  | _        t        |   |||       y)a  
        Initialize a handler.

        If address is specified as a string, a UNIX socket is used. To log to a
        local syslogd, "WebsockifySysLogHandler(address="/dev/log")" can be
        used. If facility is not specified, LOG_USER is used. If socktype is
        specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific
        socket type will be used. For Unix sockets, you can also specify a
        socktype of None, in which case socket.SOCK_DGRAM will be used, falling
        back to socket.SOCK_STREAM. If ident is specified, this string will be
        used as the application name in all messages sent. Set legacy to True
        to use the old version of the protocol.
        TN)ident_legacy_legacy_head_fmt	_head_fmtsuper__init__)selfaddressfacilitysocktyper
   legacy	__class__s         :/usr/lib/python3/dist-packages/websockify/sysloghandler.pyr   z WebsockifySysLogHandler.__init__   s4    " 
DL!22DN(H5    c                    	 | j                  |      j                  | j                  d      }|sy| j                  | j                  | j                  |j                              }t        j                  | j                  t        j                               }t        j                         d| j                   }| j                  r| j                  d| j                   }nd}t!        j"                         }|||||d} | j$                  j                   d	i |j'                  dd      }		 |	|j'                  d      z  }	| j*                  t        j,                  k7  rK| j.                  r!dt1        |	      z  j'                  d      |	z   }	n|	| j                  j'                  d      z  }	| j2                  r	 | j                  j5                  |	       y| j*                  t        j,                  k(  r'| j                  j=                  |	| j:                         y| j                  j?                  |	       y# t(        $ r |	|j'                  d      z  }	Y w xY w# t        j6                  $ r9 | j9                  | j:                         | j                  j5                  |	       Y yw xY w# t@        tB        f$ r   | jE                  |       Y yxY w)
z
        Emit a record.

        The record is formatted, and then sent to the syslog server. If
        exception information is present, it is NOT sent to the server.
         N )pri	timestamphostnamer
   pidasciiignorez	utf-8-sigz%d  )#formatreplace_tailencodePriorityr   mapPriority	levelnametimestrftime_timestamp_fmtgmtimesocketgethostname_max_hostnamer
   
_max_identosgetpidr   encodeUnicodeEncodeErrorr   
SOCK_DGRAM_send_lengthlen
unixsocketsenderror_connect_unixsocketr   sendtosendallKeyboardInterrupt
SystemExithandleError)
r   recordtextr   r   r   r
   r   headmsgs
             r   emitzWebsockifySysLogHandler.emit2   sI   <	%;;v&..tzz3?D%%dmm&*&6&6v7G7G&HJC d&9&94;;=II))+,?T-?-?@Hzz

#3DOO4))+C &$D ($..''/$/66wIC0t{{7++
 }} 1 11$$ 3s8+33G<sBC4::,,W55C *KK$$S) ==F$5$55KK&&sDLL9KK'',- & 0t{{;//0 || *,,T\\:KK$$S)* ":. 		%V$sb   -J! C8J! )H. =A4J! 2I AJ! J! .IJ! IJ! A	JJ! JJ! !"K)__name__
__module____qualname____doc__r   _rfc5424_head_fmtr   r   r*   r.   r/   r5   r$   r
   handlersSYSLOG_UDP_PORTSysLogHandlerLOG_USERr   rD   __classcell__)r   s   @r   r   r      sq    
 1L!IG)NMJLE E !,X-E-EF"0099d564D%r   r   )logging.handlersrJ   r,   r0   r(   rL   r   r!   r   r   <module>rP      s"    5 5 5r%h44 r%r   