使用Python并发尾部多个文件并推送日志到Facebook/Scribe

2 投票
1 回答
1055 浏览
提问于 2025-04-17 08:45

我想用Python同时查看多个文件的最新内容,并把这些日志发送到对应的存储桶里。

我通过以下方式获取存储桶:

dict(Config.items('files')).keys()

我通过以下方式获取文件:

dict(Config.items('files')).values()

我想同时查看所有文件的最新内容,然后把日志推送到特定的存储桶里:

log_entry = scribe.LogEntry(category, message)

socket = TSocket.TSocket(host='localhost', port=1463)
transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(trans=transport, strictRead=False, strictWrite=False)
client = scribe.Client(iprot=protocol, oprot=protocol)

transport.open()
result = client.Log(messages=[log_entry])
transport.close()

1 个回答

3

这是David Beazley关于Python生成器的一场非常不错的讲座,他提供了一些非常相关的例子,包括尾部的示例实现:http://www.slideshare.net/dabeaz/python-generator-hacking/82

撰写回答