graypy.rabbitmq module

Logging Handler integrating RabbitMQ and Graylog Extended Log Format (GELF)

class graypy.rabbitmq.ExcludeFilter(name)[source]

Bases: logging.Filter

A subclass of logging.Filter which should be instantiated with the name of the logger which, together with its children, will have its events excluded (filtered out)

__init__(name)[source]

Initialize the ExcludeFilter

Parameters

name (str) – Name to match for within a logging.LogRecord’s name field for filtering.

filter(record)[source]

Determine if the specified record is to be logged.

Is the specified record to be logged? Returns 0 for no, nonzero for yes. If deemed appropriate, the record may be modified in-place.

class graypy.rabbitmq.GELFRabbitHandler(url, exchange='logging.gelf', exchange_type='fanout', virtual_host='/', routing_key='', **kwargs)[source]

Bases: graypy.handler.BaseGELFHandler, logging.handlers.SocketHandler

RabbitMQ / GELF handler

Note

This handler ignores all messages logged by amqplib.

__init__(url, exchange='logging.gelf', exchange_type='fanout', virtual_host='/', routing_key='', **kwargs)[source]

Initialize the GELFRabbitHandler

Parameters
  • url (str) – RabbitMQ URL (ex: amqp://guest:guest@localhost:5672/)

  • exchange (str) – RabbitMQ exchange. A queue binding must be defined on the server to prevent GELF logs from being dropped.

  • exchange_type (str) – RabbitMQ exchange type.

  • virtual_host (str) –

  • routing_key (str) –

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

bytes

makeSocket(timeout=1)[source]

A factory method which allows subclasses to define the precise type of socket they want.

class graypy.rabbitmq.RabbitSocket(cn_args, timeout, exchange, exchange_type, routing_key)[source]

Bases: object

__init__(cn_args, timeout, exchange, exchange_type, routing_key)[source]

Initialize self. See help(type(self)) for accurate signature.

close()[source]

Close the connection to the RabbitMQ socket

sendall(data)[source]