#!/usr/bin/python
import sys
from scribe import scribe
from thrift.transport import TTransport, TSocket
from thrift.protocol import TBinaryProtocol
if len(sys.argv) == 2:
category = sys.argv[1]
host = '127.0.0.1'
port = 1463
elif len(sys.argv) == 4 and sys.argv[1] == '-h':
category = sys.argv[3]
host_port = sys.argv[2].split(':')
host = host_port[0]
if len(host_port) > 1:
port = int(host_port[1])
else:
port = 1463
else:
sys.exit('usage (message is stdin): scribe_cat [-h host[:port]] category')
socket = TSocket.TSocket(host=host, port=port)
transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(trans=transport, strictRead=False, strictWrite=False)
transport.open()
#log_entry = scribe.LogEntry(category=category, message=sys.stdin.read())
message = '%s'%raw_input()
while True:
log_entry = scribe.LogEntry(category=category, message=message)
client = scribe.Client(iprot=protocol, oprot=protocol)
result = client.Log(messages=[log_entry])
message = '%s'%raw_input()