码迷,mamicode.com
首页 > 编程语言 > 详细

python的scribe client

时间:2016-02-05 18:31:25      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

在网上找了一个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.")

 

python的scribe client

标签:

原文地址:http://www.cnblogs.com/tenghuan/p/5182981.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!