Posted at

pythonからfluentdを使う

More than 5 years have passed since last update.

fluentdはinstallされた状態を前提

(参考) http://qiita.com/items/c89b53301a540be72744

ライブラリをinstall

pip install fluent-logger

configを修正

<source>

type forward
port 24224
</source>
<match fluent.test.**>
type stdout
</match>

起動

fluentd -c ./fluent/fluent.conf -vv &

python script

#! /usr/local/bin/python

# -*- coding:utf-8 -*-

from fluent import sender
from fluent import event

# params -> *(tag, host, port)
sender.setup('fluent.test', host='localhost', port=24224)
event.Event('follow', {
'from': 'userA',
'to': 'userB'
})

実行すると

2013-03-20 11:44:07 +0900 fluent.test.follow: {"to":"userB","from":"userA"}

と出力