class MyZeroMQSubscriber:

  def __init__(self, socket):
    self.subscriber = ZeroMQSubscriber(socket)

  def startSubscriber(self):
    with TimedRotatingFileHandler('/home/asmi/compute/subscriber1/foo.log', date_format='%Y-%m-%d %H:%M'):
      self.subscriber.dispatch_forever()
class TriggerSubscriber:

  def __init__(self):
    print "subscriber initiated"
    # multi = True for bind() call on socket
    self.subscriber = ZeroMQSubscriber(Constants.getSocket(), multi = True)

  def startSubscriber(self, filepath):
    print "subscriber started"
    with GmailHandler("*****@*****.**", "asmi9971026789", "*****@*****.**"):
      print "log received : ", self.subscriber.recv()
      self.subscriber.dispatch_forever()
class MyZeroMQSubscriber:

  def __init__(self):
    print "subscriber initiated"
    # multi = True for bind() call on socket
    try:	
      self.subscriber = ZeroMQSubscriber(Constants.getSocket(), multi = True)
    except zmq.error.ZMQError as error:
      print "error while binding to socket :" + Constants.getSocket()
      raise zmq.error.ZMQError("error while binding to socket :" + Constants.getSocket())

  def startSubscriber(self, filepath):
    print "subscriber started" + `self.subscriber`
    with TimedRotatingFileHandler(filepath, date_format='%Y-%m-%d %H:%M'):
      print "log received : " + self.subscriber.recv().message
      self.subscriber.dispatch_forever()
Example #4
0
LOGDIR =  ConfigReader.getValue(SECTION, "LogDir") #sys.argv[2]
FILENAME = ConfigReader.getValue(SECTION, "Filename") #sys.argv[3]
SOCKET = ConfigReader.getValue(SECTION, "Socket") #sys.argv[4]
HOSTNAME = socket.gethostname()

print "SERVICE - ", SERVICE
print "LOGDIR - ", LOGDIR
print "FILENAME - ", FILENAME
print "SOCKET - ", SOCKET
print "HOSTNAME - ", HOSTNAME

subscriber = None

try:
  subscriber = ZeroMQSubscriber(SOCKET, multi = True)
  print "Subscriber bind to socket - ", SOCKET
except zmq.error.ZMQError as error:
      print "error in service " + SERVICE + " while binding to socket :" + SOCKET
      raise zmq.error.ZMQError("error in service " + SERVICE + " while binding to socket :" + SOCKET)                                                                                                                                                                                           
path = os.path.join(os.path.join(LOGDIR, HOSTNAME), SERVICE)
path_with_filename = os.path.join(path, FILENAME)
print "PATH - ", path

if not os.path.exists(path):
  os.makedirs(path)

with TimedRotatingFileHandler(path_with_filename, date_format='%Y-%m-%d %H:%M'):
  print "Log Received - ", subscriber.recv().message
  subscriber.dispatch_forever()