在网上找了一个python的scribe client使用方法
依赖的模块:
pip install facebook-scribe pip install thrift
代码例子:
#!/usr/bin/python import sys from scribe import scribe from thrift.transport import TTransport, TSocket from thrift.protocol import TBinaryProtocol category = "test_log" host = "127.0.0.1" port = "6666" message = "hello world\n" log_entry = scribe.LogEntry(category, message) socket = TSocket.TSocket(host=host, port=port) 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() if result == scribe.ResultCode.OK: sys.exit() elif result == scribe.ResultCode.TRY_LATER: print >> sys.stderr, "TRY_LATER" sys.exit(84) # ‘T‘ else: sys.exit("Unknown error code.")
时间: 2024-10-21 08:59:44