Lumberjack Song - Monty Python - YouTube

Python Lumberjack

Lumberjacks Culture / December 17, 2016

Module for integrating Elasticsearch into Python’s signing collection.

class lumberjack.Lumberjack(hosts=None, elasticsearch=None, config=None)

Here is the initialisation point for using the lumberjack library.

Into the intended use-case, this class is instantiated when and produces handlers for usage with Python’s logging component.

Per types of sign you want to keep, you really need to offer a schema. In the event that you don’t, nothing bad may happen, however it tends to make your group instead space-inefficient automagically.

You ought to offer either a summary of Elasticsearch hosts, or an already-instantiated Elasticsearch item from elasticsearch-py.

  • hosts – A list of Elasticsearch nodes to get in touch to, inside kind [{'host': '127.0.0.1', 'port': 9200}]. This can be passed away right to elasticsearch.Elasticsearch.
  • elasticsearch – as an option to hosts, an already-instantiated elasticsearch.Elasticsearch item, possibly with customized transports etc.
  • config – a setup for Lumberjack. Look at setup part within the docs for details.
get_handler(suffix_format='percentY.%m')

Spawn a logging handler.

You need to use this technique to obtain a logging.Handler item to add to a logging.Logger object.

Note: It's virtually absolutely unwise setting the formatter of the handler your self. The incorporated formatter prepares papers prepared be inserted into Elasticsearch.
Parameters: suffix_format – The time format string to make use of while the suffix when it comes to indices. Automagically your indices will be known as, e.g., generic-logging-2014.09.
register_schema(logger, schema)

Enter a log entry schema.

It really is a smart idea to register a ‘schema’ for every single logger that you connect a handler to. It will help Elasticsearch shop the data you offer optimally.

This technique will stop before mapping is subscribed with Elasticsearch, therefore you should do it inside initialisation.

  • logger – The name regarding the logger this schema will affect.
  • schema – The schema to be utilized.
trigger_flush

By hand trigger a flush associated with the sign queue.

This isn't going to flush immediately; it just cancels the delay ahead of the after that flush into the ActionQueue bond.

Source: lumberjack.readthedocs.io