Skip to main content

A Python logging handler for Fluent event collector

Project description

# A Python structured logger for Fluent


Many web/mobile applications generate huge amount of event logs (c,f. login, logout, purchase, follow, etc). To analyze these event logs could be really valuable for improving the service. However, the challenge is collecting these logs easily and reliably.

[Fluent](http://github.com/fluent/fluent) solves that problem by having: easy installation, small footprint, plugins, reliable buffering, log forwarding, etc.

**fluent-logger-python** is a Python library, to record the events from Python application.

## Installation

This library is distributed as 'fluent-logger' python package. Please execute the following command to install it.

$ pip install fluent-logger

## Configuration

Fluent daemon must be lauched with the following configuration:

<source>
type tcp
port 24224
</source>

## Usage

### Event-Based Interface

First, you need to call logger.setup() to create global logger instance. This call needs to be called only once, at the beggining of the application for example.

By default, the logger assumes fluent daemon is launched locally. You can also specify remote logger by passing the options.

from fluent import sender

# for local fluent
sender.setup('app')

# for remote fluent
sender.setup('app', server='host', port='24224')

Then, please create the events like this. This will send the event to fluent, with tag 'app.follow' and the attributes 'from' and 'to'.

from fluent import event

# send event to fluentd, with 'app.follow' tag
event.Event('follow', {
'from': 'userA',
'to': 'userB'
})

### Python logging.Handler interface

This client-library also has FluentHanler class for Python logging module.

import logging
from fluent import handler

logging.basicConfig(level=logging.INFO)
l = logging.getLogger('fluent.test')
l.addHandler(handler.FluentHandler('app.follow'))
l.info({
'from': 'userA',
'to': 'userB'
})

## License

Apache License, Version 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fluent-logger-0.2.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file fluent-logger-0.2.0.tar.gz.

File metadata

File hashes

Hashes for fluent-logger-0.2.0.tar.gz
Algorithm Hash digest
SHA256 105a018e9f19c173527c83a4817666a4ed2f98244c3001b11d8d232f1a5bbcdf
MD5 3edf1cd026db07ed0be0caea37324f1a
BLAKE2b-256 7b1c058c080ce2b1ca4c50b9f70f0c6b01668b0830d449f9ee17ca8cb3be94aa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page