HEX
Server: LiteSpeed
System: Linux srv146.niagahoster.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: kodi1989 (1633)
PHP: 8.1.34
Disabled: symlink,shell_exec,exec,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/fluent/__pycache__/handler.cpython-37.pyc
B

��f%"�@sLddlZddlZddlZddlmZGdd�dej�ZGdd�dej�ZdS)�N)�sendercsveZdZdZd�fdd�	Z�fdd	�Zd
d�Zdd
�Zdd�Z�fdd�Z	dd�Z
dd�Zdd�Ze
dd��Z�ZS)�FluentRecordFormattera6A structured formatter for Fluent.

    Best used with server storing data in an ElasticSearch cluster for example.

    :param fmt: a dict or a callable with format string as values to map to provided keys.
        If callable, should accept a single argument `LogRecord` and return a dict,
        and have a field `usesTime` that is callable and return a bool as would
        `FluentRecordFormatter.usesTime`
    :param datefmt: strftime()-compatible date/time format string.
    :param style: '%', '{' or '$' (used only with Python 3.2 or above)
    :param fill_missing_fmt_key: if True, do not raise a KeyError if the format
        key is not found. Put None if not found.
    :param format_json: if True, will attempt to parse message as json. If not,
        will use message as-is. Defaults to True
    :param exclude_attrs: switches this formatter into a mode where all attributes
        except the ones specified by `exclude_attrs` are logged with the record as is.
        If `None`, operates as before, otherwise `fmt` is ignored.
        Can be an iterable.
    N�%FTcst��d|�|dkrHtjdddd�ftjdddd�fd	�|\|_}nd|_d
ddd�}|dk	r�t|�|_d|_|j	|_
t�j|_nPd|_|s�||_|j|_
|j
|_n.t|�r�||_
|j|_n||_|j|_
|j
|_|r�|j|_n|j|_t��|_||_dS)
Nrz
{hostname}z{name}z{module})Zsys_hostZsys_name�
sys_modulez${hostname}z${name}z	${module})�{�$z%(hostname)sz%(name)sz
%(module)s)�super�__init__�logging�StrFormatStyle�StringTemplateStyle�_FluentRecordFormatter__style�set�
_exc_attrs�	_fmt_dict�_format_by_exclusion�
_formatter�usesTime�_format_by_dict�_format_by_dict_uses_time�callable�_format_msg_json�_format_msg�_format_msg_default�socket�gethostname�hostname�fill_missing_fmt_key)�self�fmt�datefmt�stylerZformat_jsonZ
exclude_attrsZbasic_fmt_dict)�	__class__��?/opt/alt/python37/lib/python3.7/site-packages/fluent/handler.pyr	sH	




zFluentRecordFormatter.__init__cs.t��|�|j|_|�|�}|�||�|S)N)r�formatrr�_structuring)r�record�data)r"r#r$r%`s

zFluentRecordFormatter.formatcCsdS)zTThis method is substituted on construction based on settings for performance reasonsNr#)rr#r#r$rlszFluentRecordFormatter.usesTimecCsR|j}t|t�r|�||�n0t|t�r>|�||�||��n|�|d|i�dS)a|Melds `msg` into `data`.

        :param data: dictionary to be sent to fluent server
        :param msg: :class:`LogRecord`'s message to add to `data`.
          `msg` can be a simple string for backward compatibility with
          :mod:`logging` framework, a JSON encoded string or a dictionary
          that will be merged into dictionary generated in :meth:`format.
        �messageN)�msg�
isinstance�dict�_add_dic�strr)rr(r'r*r#r#r$r&os	

z"FluentRecordFormatter._structuringcCsNy,t�t|��}t|t�r|S|�||�SWntk
rH|�||�SXdS)N)�json�loadsr.r+r,r�
ValueError)rr'r*Zjson_msgr#r#r$r�s
z&FluentRecordFormatter._format_msg_jsoncsdt��|�iS)Nr))rr%)rr'r*)r"r#r$r�sz)FluentRecordFormatter._format_msg_defaultcCs2i}x(|j��D]\}}||jkr|||<qW|S)N)�__dict__�itemsr)rr'r(�key�valuer#r#r$r�s

z*FluentRecordFormatter._format_by_exclusioncCs�i}xv|j��D]h\}}y&|jr2|�|��|�}n
||j}Wn0tk
rn}zd}|js^|�Wdd}~XYnX|||<qW|S)N)rr3r
r%r2�KeyErrorr)rr'r(r4r5�excr#r#r$r�sz%FluentRecordFormatter._format_by_dictcs0|jr|jj�nd�t�fdd�|j��D��S)Nz
%(asctime)csg|]}|���dk�qS)r)�find)�.0r5)�searchr#r$�
<listcomp>�szCFluentRecordFormatter._format_by_dict_uses_time.<locals>.<listcomp>)r
�asctime_search�anyr�values)rr#)r:r$r�s
z/FluentRecordFormatter._format_by_dict_uses_timecCs,x&|��D]\}}t|t�r
|||<q
WdS)N)r3r+r.)r(Zdicr4r5r#r#r$r-�s
zFluentRecordFormatter._add_dic)NNrFTN)�__name__�
__module__�__qualname__�__doc__r	r%rr&rrrrr�staticmethodr-�
__classcell__r#r#)r"r$rs <
rcs^eZdZdZddd�Zd	d
�Zedd��Zd
d�Zdd�Z	�fdd�Z
dd�Zdd�Z�Z
S)�
FluentHandlerz%
    Logging Handler for fluent.
    �	localhost�^�@FNc	
KsL||_||_||_||_||_||_||_||_|	|_d|_	t
j�|�dS)N)
�tag�_host�_port�_timeout�_verbose�_buffer_overflow_handler�_msgpack_kwargs�_nanosecond_precision�_kwargs�_senderr
�Handlerr	)
rrI�host�port�timeout�verbose�buffer_overflow_handler�msgpack_kwargs�nanosecond_precision�kwargsr#r#r$r	�szFluentHandler.__init__cCstjS)N)rZFluentSender)rr#r#r$�getSenderClass�szFluentHandler.getSenderClasscCsF|jdkr@|jf|j|j|j|j|j|j|j|j	d�|j
��|_|jS)N)rIrTrUrVrWrXrYrZ)rR�getSenderInstancerIrJrKrLrMrNrOrPrQ)rr#r#r$r�s
zFluentHandler.senderc	
Ks(|��}
|
|f|||||||d�|	��S)N)rTrUrVrWrXrYrZ)r\)rrIrTrUrVrWrXrYrZr[Zsender_classr#r#r$r]�szFluentHandler.getSenderInstancecCs6|�|�}|j}|�d|jr(t�|j�nt|j�|�S)N)r%rZemit_with_timerZZ	EventTime�created�int)rr'r(rRr#r#r$�emit�s
zFluentHandler.emitcsH|��z0z|jdk	r&|j��d|_Wdt���XWd|��XdS)N)�acquirerR�closer�release)r)r"r#r$rbs


zFluentHandler.closecCs|S)Nr#)rr#r#r$�	__enter__szFluentHandler.__enter__cCs|��dS)N)rb)r�exc_type�exc_val�exc_tbr#r#r$�__exit__szFluentHandler.__exit__)rFrGrHFNNF)r?r@rArBr	r\�propertyrr]r`rbrdrhrDr#r#)r"r$rE�s
rE)	r/r
rZfluentr�	FormatterrrSrEr#r#r#r$�<module>s,