graypy.handler module¶
Logging Handlers that send messages in Graylog Extended Log Format (GELF)
-
class
graypy.handler.
BaseGELFHandler
(chunk_size=1420, debugging_fields=True, extra_fields=True, fqdn=False, localname=None, facility=None, level_names=False, compress=True)[source]¶ Bases:
logging.Handler
,abc.ABC
Abstract class defining the basic functionality of converting a
logging.LogRecord
into a GELF log. Provides the boilerplate for all GELF handlers defined within graypy.-
__init__
(chunk_size=1420, debugging_fields=True, extra_fields=True, fqdn=False, localname=None, facility=None, level_names=False, compress=True)[source]¶ Initialize the BaseGELFHandler.
- Parameters
chunk_size (int) – Message chunk size. Messages larger than this size will be sent to Graylog in multiple chunks.
debugging_fields (bool) – If
True
add debug fields from the log record into the GELF logs to be sent to Graylog.extra_fields (bool) – If
True
add extra fields from the log record into the GELF logs to be sent to Graylog.fqdn (bool) – If
True
use the fully qualified domain name of localhost to populate thehost
GELF field.localname (str or None) – If specified and
fqdn
isFalse
, use the specified hostname to populate thehost
GELF field.facility (str) – If specified, replace the
facility
GELF field with the specified value. Also add a additional_logger
GELF field containing theLogRecord.name
.level_names (bool) – If
True
use python logging error level name strings instead of syslog numerical values.compress (bool) – If
True
compress the GELF message before sending it to the Graylog server.
-
makePickle
(record)[source]¶ Convert a
logging.LogRecord
into bytes representing a GELF log- Parameters
record (logging.LogRecord) –
logging.LogRecord
to convert into a GELF log.- Returns
bytes representing a GELF log.
- Return type
-
-
class
graypy.handler.
ChunkedGELF
(message, size)[source]¶ Bases:
object
Class that chunks a message into a GELF compatible chunks
-
class
graypy.handler.
GELFHTTPHandler
(host, port=12203, compress=True, path='/gelf', timeout=5, **kwargs)[source]¶ Bases:
graypy.handler.BaseGELFHandler
GELF HTTP handler
-
__init__
(host, port=12203, compress=True, path='/gelf', timeout=5, **kwargs)[source]¶ Initialize the GELFHTTPHandler
- Parameters
host (str) – GELF HTTP input host.
port (int) – GELF HTTP input port.
compress (bool) – If
True
compress the GELF message before sending it to the Graylog server.path (str) – Path of the HTTP input. (see http://docs.graylog.org/en/latest/pages/sending_data.html#gelf-via-http)
timeout (int) – Number of seconds the HTTP client should wait before it discards the request if the Graylog server doesn’t respond.
-
emit
(record)[source]¶ Convert a
logging.LogRecord
to GELF and emit it to Graylog via a HTTP POST request- Parameters
record (logging.LogRecord) –
logging.LogRecord
to convert into a GELF log and emit to Graylog via a HTTP POST request.
-
-
class
graypy.handler.
GELFTCPHandler
(host, port=12201, **kwargs)[source]¶ Bases:
graypy.handler.BaseGELFHandler
,logging.handlers.SocketHandler
GELF TCP handler
-
__init__
(host, port=12201, **kwargs)[source]¶ Initialize the GELFTCPHandler
Attention
GELF TCP does not support compression due to the use of the null byte (
\0
) as frame delimiter.Thus,
handler.GELFTCPHandler
does not support settingcompress
toTrue
and is locked toFalse
.
-
makePickle
(record)[source]¶ Add a null terminator to generated pickles as TCP frame objects need to be null terminated
- Parameters
record (logging.LogRecord) –
logging.LogRecord
to create a null terminated GELF log.- Returns
Null terminated bytes representing a GELF log.
- Return type
-
-
class
graypy.handler.
GELFTLSHandler
(host, port=12204, validate=False, ca_certs=None, certfile=None, keyfile=None, **kwargs)[source]¶ Bases:
graypy.handler.GELFTCPHandler
GELF TCP handler with TLS support
-
__init__
(host, port=12204, validate=False, ca_certs=None, certfile=None, keyfile=None, **kwargs)[source]¶ Initialize the GELFTLSHandler
- Parameters
host (str) – GELF TLS input host.
port (int) – GELF TLS input port.
validate (bool) – If
True
, validate the Graylog server’s certificate. In this case specifyingca_certs
is also required.ca_certs (str) – Path to CA bundle file.
certfile (str) – Path to the client certificate file.
keyfile (str) – Path to the client private key. If the private key is stored with the certificate, this parameter can be ignored.
-
-
class
graypy.handler.
GELFUDPHandler
(host, port=12202, **kwargs)[source]¶ Bases:
graypy.handler.BaseGELFHandler
,logging.handlers.DatagramHandler
GELF UDP handler