log2http监视日志文件并将新内容发送到指定的http端点。
log2http的Python项目详细描述
日志2http
log2http监视日志文件并将新内容发送到指定的http端点。就这样。
安装
您需要python>;=3.6。
像这样安装应用程序(最好是在virtualenv中):
pip install log2http
设置
在您喜欢的位置放置如下所示的yaml配置文件:
-
logfile: /Users/demo/example.log
endpoint: http://endpoint1.example.com/tag/sample
min_lines: 5
-
logfile: /var/log/system.log
endpoint: http://endpoint2.example.com/tag/syslog
min_lines: 2
logfile
指定要监视的文件endpoint
是要将收集的日志行发送到(作为post)的http端点。通常,这将是日志服务的url,例如http://logs-01.loggly.com/bulk/token/tag/example/
min_lines
设置在发出http请求之前必须收集的最小行数(使用此选项可最小化每个记录的事件的http开销)
用法
安装后,您可以从终端启动log2http:
log2http --config=/path/to/the/config.yml
当log2http运行时,创建一些示例事件以查看是否正在收集它们。例如在bash中:
for i in {1..6}; do echo "hello world" >> example.log; done
输出应该告诉您是否正在收集和发送事件。
您还可以从python启动日志收集器,如下所示:
from log2http import load_config, LogCollector
config = load_config('/your/path/to/config.yml')
collector = LogCollector(config)
with collector:
collector.start() # will run until interrupted
注意:日志行总是需要以换行符结尾(\n
)。如果一行没有以换行符结尾,log2http将无限期地等待,直到它被写入文件。
地方发展
有关开发需求,请参见requirements-dev.txt
。
使用pytest
运行测试。
使用mypy --ignore-missing-imports log2http
运行静态类型检查。