Chinaunix首页 | 论坛 | 博客
  • 博客访问: 287781
  • 博文数量: 40
  • 博客积分: 1807
  • 博客等级: 上尉
  • 技术积分: 350
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-03 15:42
文章分类

全部博文(40)

文章存档

2011年(18)

2010年(20)

2009年(2)

我的朋友

分类: LINUX

2010-09-25 15:40:48

Logging Messages

Scribe implements the following Thrift interface:

enum ResultCode
{
OK,
TRY_LATER
}

struct LogEntry
{
1: string category,
2: string message
}

service scribe extends fb303.FacebookService
{
ResultCode Log(1: list messages);
}

To send a message to a Scribe Server running on a given machine and port, we simply need to create a Scribe Client and call Log(). Here is an example using Python:

from scribe import scribe
from thrift.transport import TTransport, TSocket
from thrift.protocol import TBinaryProtocol

category='test'
message='hello world'
log_entry = scribe.LogEntry(category, message)
# depending on thrift version
# log_entry = scribe.LogEntry(dict(category=category, message=message))

socket = TSocket.TSocket(host='localhost', port=1456)
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()

To learn more about the Thrift software framework, visit the Thrift homepage:
http://developers.facebook.com/thrift/

阅读(1320) | 评论(0) | 转发(0) |
0

上一篇:ThriftUsageC++

下一篇:NOSQL之旅---HBase

给主人留下些什么吧!~~