Git Product home page Git Product logo

influxdb_logging's Introduction

InfluxDB logging

InfluxDB is a timeseries database that is optimized for realtime insert and time-aggregated selections. It advertises itself as a logging and devops solution, but to date there was no integration with the Python logging framework. influxdb_logging rectifies that. There are two classes: InfluxHandler and BufferingInfluxHandler. They support all the options to InfluxDBClient as keyword arguments.

One significant change is that because dots are separators for databases in InfluxQL, to ensure maximum compatibility with other products that integrate InfluxDB such as InfluxDB's own clients and Grafana, we change logger separators from dots to colons on insert.

In general, the logger name is the "measurement" in InfluxDB terms, and the basic "tags" are level (syslog number) and short_message. You can add more by passing an indexed_keys= parameter to the class. Everything else that is part of the logging record will be added as fields.

These handler classes were inspired by graypy for Graylog, although by the time I was done they bear little resemblance to them.

Example Usage

from influx_logging import InfluxHandler, BufferingInfluxHandler

influx_handler = InfluxHandler(database='test_influx_handler')    
logging.getLogger().setLevel(logging.DEBUG)

influx_logger = logging.getLogger('influx_logging.tests.simple_message')
influx_logger.addHandler(influx_handler)

influx_logger.debug('Debug message')
influx_logger.info('Info message')
influx_logger.warning('Warning message')
influx_logger.error('Error message')

try:
    raise Exception("This is an exception")
except:
    influx_logger.exception('Exception message')
    
res = influx_handler.client.query(
    'SELECT * FROM "influx_logging:tests:simple_message"'
)

class InfluxHandler

Parameters
  • database: The database you want log entries to go into.
  • indexed_keys: The names of keys to be treated as keys (as opposed to fields) in influxdb.
  • debugging_fields: Send debug fields if true (the default).
  • extra_fields: Send extra fields on the log record to graylog if true (the default).
  • localname: Use specified hostname as source host.
  • measurement: Replace measurement with specified value. If not specified, record.name will be passed as logger parameter.
  • level_names: Allows the use of string error level names instead of numerical values. Defaults to False
  • backpop: Default True. Add a record for each item in the hierarchy of loggers.
  • **client_kwargs: Pass these args to the InfluxDBClient constructor

class BufferingInfluxHandler

Parameters
  • indexed_keys: The names of keys to be treated as keys (as opposed to fields) in influxdb.
  • debugging_fields: Send debug fields if true (the default).
  • extra_fields: Send extra fields on the log record to graylog if true (the default).
  • localname: Use specified hostname as source host.
  • measurement: Replace measurement with specified value. If not specified, record.name will be passed as logger parameter.
  • level_names: Allows the use of string error level names instead of numerical values. Defaults to False
  • capacity: The number of points to buffer before sending to InfluxDB.
  • flush_interval: Interval in seconds between flushes, maximum. Defaults to 5 seconds
  • backpop: Default True. Add a record for each item in the hierarchy of loggers.
  • **client_kwargs: Pass these args to the InfluxDBClient constructor

influxdb_logging's People

Contributors

jheard-tw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.