Skip to content
袁逸凡 edited this page Aug 13, 2018 · 3 revisions

Lofka for Python

简介/Introduction

(很抱歉,当时输入法崩掉了,就干脆写成英语的了,等有空翻译回来)

如果你想推送由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.

安装/Setup

首先切换到文件夹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

快速开始/Quick Start

导入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)

细节/Details

More details will described below.

LofkaHandler的配置/Setting of LofkaHandler

可以通过在你的工作目录下创建名为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会按照如下优先级加载配置:

  1. 工作目录中的lofka.json
  2. LofkaHandler加载时候的参数
  3. 默认参数

The priority of LofkaHandler setting will load:

  1. lofka.json in current workdir
  2. parameters inputted while loading LofkaHandler
  3. default parameters
Clone this wiki locally