blob: b382ed9955d54fe676a6d89a7be17e921b197773 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/usr/bin/python
# scribe_client.py
from scribe import scribe
from thrift.transport import TTransport, TSocket
from thrift.protocol import TBinaryProtocol
class ScribeClient(object):
def __init__(self, port, host):
print host
self.port = port
self.host = host
self.openConnection()
def openConnection(self):
socket = TSocket.TSocket(host=self.host, port=self.port)
self.transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(trans=self.transport,
strictRead=False,
strictWrite=False)
self.client = scribe.Client(protocol)
self.transport.open()
def log(self, category, message):
log_entry = scribe.LogEntry(category, message)
result = self.client.Log(messages=[log_entry])
return result # 0 for success
def close(self):
self.transport.close()
|