gale.log.graylog_handler module

This file contains the implementation of the class GraylogHandler: a logging.Handler that sends each log record to a Graylog server as a GELF (Graylog Extended Log Format) datagram over UDP.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.log.graylog_handler.GraylogHandler(host, port, source=None)[source]

Bases: Handler

Sends every log record to a Graylog server as a GELF (Graylog Extended Log Format) datagram over UDP — one strategy among possibly several; register it with gale.log.add_handler to start sending records there in addition to (or, with gale.log.configure(console=False, log_file=None), instead of) the console/file defaults. Any other logging.Handler works exactly the same way, GraylogHandler is just the one gale ships since the standard library doesn’t have one.

Usage example:

from gale.log import add_handler from gale.log.graylog_handler import GraylogHandler

add_handler(GraylogHandler(“graylog.example.com”, 12201))

Parameters:
  • host (str)

  • port (int)

  • source (str | None)

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

Parameters:

record (LogRecord)

Return type:

None

close()[source]

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

Return type:

None