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