A Python logging handler for Fluentd event collector
Project description
# A Python structured logger for Fluentd
[![Build Status](https://travis-ci.org/fluent/fluent-logger-python.svg?branch=master)](https://travis-ci.org/fluent/fluent-logger-python)
[![Coverage Status](https://coveralls.io/repos/fluent/fluent-logger-python/badge.svg)](https://coveralls.io/r/fluent/fluent-logger-python)
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.
[Fluentd](http://github.com/fluent/fluentd) 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.
## Requirements
* Python 2.6 or greater including 3.x
## Installation
This library is distributed as 'fluent-logger' python package. Please execute the following command to install it.
```sh
$ pip install fluent-logger
```
## Configuration
Fluentd daemon must be launched with a tcp source configuration:
<source>
type forward
port 24224
</source>
To quickly test your setup, add a matcher that logs to the stdout:
<match app.**>
type stdout
</match>
## 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 fluentd daemon is launched locally. You can also specify remote logger by passing the options.
```python
from fluent import sender
# for local fluent
sender.setup('app')
# for remote fluent
sender.setup('app', host='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'.
```python
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 `FluentHandler` class for Python logging module.
```python
import logging
from fluent import handler
logging.basicConfig(level=logging.INFO)
l = logging.getLogger('fluent.test')
h = handler.FluentHandler('app.follow', host='host', port=24224)
h.setFormatter(handler.FluentRecordFormatter())
l.addHandler(h)
l.info({
'from': 'userA',
'to': 'userB'
})
```
## Testing
Testing can be done using [nose](https://nose.readthedocs.org/en/latest/).
## Contributors
Patches contributed by [those people](https://github.com/fluent/fluent-logger-python/contributors).
## License
Apache License, Version 2.0
[![Build Status](https://travis-ci.org/fluent/fluent-logger-python.svg?branch=master)](https://travis-ci.org/fluent/fluent-logger-python)
[![Coverage Status](https://coveralls.io/repos/fluent/fluent-logger-python/badge.svg)](https://coveralls.io/r/fluent/fluent-logger-python)
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.
[Fluentd](http://github.com/fluent/fluentd) 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.
## Requirements
* Python 2.6 or greater including 3.x
## Installation
This library is distributed as 'fluent-logger' python package. Please execute the following command to install it.
```sh
$ pip install fluent-logger
```
## Configuration
Fluentd daemon must be launched with a tcp source configuration:
<source>
type forward
port 24224
</source>
To quickly test your setup, add a matcher that logs to the stdout:
<match app.**>
type stdout
</match>
## 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 fluentd daemon is launched locally. You can also specify remote logger by passing the options.
```python
from fluent import sender
# for local fluent
sender.setup('app')
# for remote fluent
sender.setup('app', host='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'.
```python
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 `FluentHandler` class for Python logging module.
```python
import logging
from fluent import handler
logging.basicConfig(level=logging.INFO)
l = logging.getLogger('fluent.test')
h = handler.FluentHandler('app.follow', host='host', port=24224)
h.setFormatter(handler.FluentRecordFormatter())
l.addHandler(h)
l.info({
'from': 'userA',
'to': 'userB'
})
```
## Testing
Testing can be done using [nose](https://nose.readthedocs.org/en/latest/).
## Contributors
Patches contributed by [those people](https://github.com/fluent/fluent-logger-python/contributors).
## License
Apache License, Version 2.0
Project details
Release history Release notifications | RSS feed
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.4.0.tar.gz
(5.2 kB
view details)
File details
Details for the file fluent-logger-0.4.0.tar.gz
.
File metadata
- Download URL: fluent-logger-0.4.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ac7d727744981cac1f1770074b81539a59655792efde1f57c84d0ca3c38b4e1 |
|
MD5 | 9d4c552c7b05db905a842024bac0b8b7 |
|
BLAKE2b-256 | 12576cf7dc19028d0b8b1f0d24ffaababff089bd1d1a4beb88a2f87303c331f1 |