File: //opt/alt/python37/lib/python3.7/site-packages/graypy/__pycache__/handler.cpython-37.pyc
B
�P�e�e �
@ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlmZmZ dZdZejd dkr�ee ZZn
ee ZZejdkr�ejZne�ed�d i �ZyddlZW n ek
r� ddlmZ Y nX ejd
ej dej!dej"dej#d
iZ$dZ%G dd� dej&e�Z'G dd� de(�Z)G dd� de*�Z+G dd� de)�Z,G dd� de+�Z-G dd� de)�Z.G dd� de'e�Z/G dd� de'e�Z0G dd � d e0�Z1G d!d"� d"e'�Z2dS )#zILogging Handlers that send messages in Graylog Extended Log Format (GELF)� N)�DatagramHandler�
SocketHandleri� i� � )r � �ABC� � r � � � c @ s� e Zd ZdZddd�Zdd� Zd d
� Zedd� �Zed
d� �Z edd� �Z
edd� �Zedd� �Zedd� �Z
edd� �Zedd� �Zedd� �ZdS )�BaseGELFHandlerz�Abstract class defining the basic functionality of converting a
:obj:`logging.LogRecord` into a GELF log. Provides the boilerplate for
all GELF handlers defined within graypy.TFNc C sJ t j�| � || _|| _|r(|r(td��|| _|| _|| _|| _ || _
dS )a� Initialize the BaseGELFHandler
:param debugging_fields: If :obj:`True` add debug fields from the
log record into the GELF logs to be sent to Graylog.
:type debugging_fields: bool
:param extra_fields: If :obj:`True` add extra fields from the log
record into the GELF logs to be sent to Graylog.
:type extra_fields: bool
:param fqdn: If :obj:`True` use the fully qualified domain name of
localhost to populate the ``host`` GELF field.
:type fqdn: bool
:param localname: If specified and ``fqdn`` is :obj:`False`, use the
specified hostname to populate the ``host`` GELF field.
:type localname: str or None
:param facility: If specified, replace the ``facility`` GELF field
with the specified value. Also add a additional ``_logger``
GELF field containing the ``LogRecord.name``.
:type facility: str
:param level_names: If :obj:`True` use python logging error level name
strings instead of syslog numerical values.
:type level_names: bool
:param compress: If :obj:`True` compress the GELF message before
sending it to the Graylog server.
:type compress: bool
z8cannot specify 'fqdn' and 'localname' arguments togetherN)�logging�Handler�__init__�debugging_fields�extra_fields�
ValueError�fqdn� localname�facility�level_names�compress)�selfr r r r r r r r r �?/opt/alt/python37/lib/python3.7/site-packages/graypy/handler.pyr 9 s )zBaseGELFHandler.__init__c C s, | � |�}| �|�}| jr$t�|�n|}|S )a Convert a :class:`logging.LogRecord` into bytes representing
a GELF log
:param record: :class:`logging.LogRecord` to convert into a GELF log.
:type record: logging.LogRecord
:return: bytes representing a GELF log.
:rtype: bytes
)�_make_gelf_dict�_pack_gelf_dictr �zlib)r �record� gelf_dict�packed�pickler r r �
makePickleo s
zBaseGELFHandler.makePicklec C s� d| � | j| j�| jr"| j�|�n|�� |jt�|j |j �| j
pD|jd�}| �||� | j
rh| �||� | j
dk r�| �|| j
|� | jr�| �||� | jr�| �||� |S )a& Create a dictionary representing a GELF log from a
python :class:`logging.LogRecord`
:param record: :class:`logging.LogRecord` to create a GELF log from.
:type record: logging.LogRecord
:return: Dictionary representing a GELF log.
:rtype: dict
z1.0)�version�host�
short_message� timestamp�levelr N)�
_resolve_hostr r � formatter�format�
getMessage�created�
SYSLOG_LEVELS�get�levelnor �name�_add_full_messager �_add_level_names�_set_custom_facilityr �_add_debugging_fieldsr �_add_extra_fields)r r r r r r r ~ s"