# A Python structured logger for Fluentd
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.
$ pip install fluent-logger
## Configuration
Fluentd daemon must be lauched with the following configuration:
<source>
type tcp
port 24224
</source>
<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.
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'.
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', host='host', port=24224))
l.info({
'from': 'userA',
'to': 'userB'
})
### Pyramid logging configuration
First, setup a fluent log formatter.
Note the different format of "format".
[formatter_fluent]
class = fluent.handler.FluentRecordFormatter
format =
levelname
name
#datefmt = %H:%M:%S (fluentd native date format is used instead)
Then, setup a fluent handler.
class = fluent.handler.FluentHandler
args = ("<Your log tag>",)
level = INFO
formatter = fluent
Finally, add the fluent handler to handler list.
[handlers]
keys = generic, fluent
## Contributors
Patches contributed by [those people](https://github.com/fluent/fluent-logger-python/contributors).
## License
Apache License, Version 2.0
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:fluent-logger-pyramid-0.0.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源详情
资源评论
资源推荐
收起资源包目录
fluent-logger-pyramid-0.0.3.tar.gz (15个子文件)
fluent-logger-pyramid-0.0.3
MANIFEST.in 51B
PKG-INFO 4KB
fluent_logger_pyramid.egg-info
PKG-INFO 4KB
requires.txt 25B
SOURCES.txt 332B
top_level.txt 7B
dependency_links.txt 1B
setup.cfg 59B
setup.py 954B
fluent
__init__.py 0B
sender.py 3KB
handler.py 2KB
event.py 374B
README.md 3KB
COPYING 591B
共 15 条
- 1
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0