-
Notifications
You must be signed in to change notification settings - Fork 18
Python
(很抱歉,当时输入法崩掉了,就干脆写成英语的了,等有空翻译回来)
如果你想推送由Python程序产生的日志到Lofka,你应该正确地安装此模块。
If you wanna to push your logs generated by a Python program, you may install this module after setup your lofka system appropriately.
需要注意的是,本程序同时支持Python2和3。
This module support python2/3.
首先切换到文件夹lofka-python-utils
,并且运行如下指令:
Change dir to lofka-python-utils, and run command:
sudo python setup.py install
# if you're using python3
sudo python3 setup.py install
导入Lofka句柄(求求各位菊苣,给Handler赐一个好点的翻译)并且将其添加到你的Logger:
Import lofka handler and add it to your logger:
from lofka import LofkaHandler
import logging
handler = LofkaHandler()
logger = logging.getLogger('test')
logger.addHandler(handler)
More details will described below.
可以通过在你的工作目录下创建名为lofka.json
的JSON文件来配置LofkaHandler
。
Setting LofkaHandler by creating a json file which named:lofka.json
in your workdir.
{
"target_url": "http://logger.example.com/",
"app_name": "test"
}
通过配置app_name
字段来配置应用名称,通过配置target_url
字段配置推送目标。
Setting the target to push logs by the field target_url
and the application name by field app_name
.
或者你可以使用参数来初始化LofkaHandler:
Or you can set these parameters while initializing LofkaHandler:
handler = LofkaHandler(target_url='http://logger.example.com/', app_name="test")
LofkaHandler会按照如下优先级加载配置:
- 工作目录中的
lofka.json
- LofkaHandler加载时候的参数
- 默认参数
The priority of LofkaHandler setting will load:
-
lofka.json
in current workdir - parameters inputted while loading LofkaHandler
- default parameters