jmrobles / fluent-http

Fluent over Http Python logging handler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fluent HTTP Python Logger Handler

A logger handler for fluentd logging collector.

How to use it

import logging
from fluent_http import FluentHttpHandler

logger = logging.getLogger(__name__)
fluent_http_handler = FluentHttpHandler(url='localhost', port=9880, tag='app.python')
logger.addHandler(fluent_http_handler)

# Test it!
logger.warning('Houston, we have a problem')

JSON logging

Install python-json-logger before

pip install python-json-logger
import logging
from pythonjsonlogger import jsonlogger
from fluent_http import FluentHttpHandler

logger = logging.getLogger(__name__)
fluent_http_handler = FluentHttpHandler(url='localhost', port=9880, tag='app.python')
fluent_http_handler.setFormatter(jsonlogger.JsonFormatter(timestamp=True))
logger.addHandler(fluent_http_handler)
logger.setLevel(logging.INFO)
# Test it!
logger.info('purchase done', extra={'item_id': 12345, 'quantity': 4, 'total_price': 32412})

Protected under Auth Basic HTTP

...
fluent_http_handler = FluentHttpHandler(url='https://fluent.example.com', port=443, tag='app.python', username='user', password='a_password')
...

License

MIT License

About

Fluent over Http Python logging handler

License:MIT License


Languages

Language:Python 100.0%