class LogHandler:

  def __init__ (self, service):
    self.handler = Handler(service)
    self.logger = self.handler.getLogHandler()
    # get queue handler for logging
    self.queueHandler = self.handler.getQueueHandler()
    # start queue subscriber for logging 
    self.handler.startQueueSubscriber()
    self.service = service
    self.setHost()
    self.setZone()
    self.setRegion()
    self.commonLog = Constants.toStringCommon(self.region, self.zone, self.host, self.service)

  def appendLog (self, msg):
    try:
      with queueHandler:
        self.logger.info(self.commonLog+msg)
    except:
      #monitorLog.logError("Cannot write to file " + self.filepath)
      pass

  def appendCountLog(self, name, metricType, count):
    msg = Constants.toStringCount(name, metricType, count)
    self.appendLog(msg)

  def appendTimeLog(self, name, metricType, runtime):
    msg = Constants.toStringRuntime(name, metricType, runtime)
    self.appendLog(msg)

  '''
    Set host from metadata.
  '''
  def setHost(self):
    try:
      self.host = "demo_host"
    except:
      pass


  '''
    Set zone from metadata.
  '''    
  def setZone(self):
    try:
      self.zone = "demo_zone"
    except:
      pass


  '''
    Set region from metadata.
  '''
  def setRegion(self):
    try:
      self.region = "demo_region"
    except:
      pass
Beispiel #2
0
class LogHandler:

  def __init__ (self, service, configFile):
    self.service = service
    try:
      self.handler = Handler(self.service, configFile)
      self.logger = self.handler.getLogHandler()
      print "handler returned logger instance"
    except Exception as error:
      monitorLog.logError("Cannot Instantiate Handler with configFile : " + configFile, `error`)
      raise Exception("Cannot Instantiate Handler with configFile : " + configFile)
    ''' Subscriber is now an independent process , hence following lines are commented '''
    # start queue subscriber for logging 
    #self.handler.startQueueSubscriber()
    # get queue handler for logging
    try:
      self.queueHandler = self.handler.getQueueHandler()
    except Exception as error:
      monitorLog.logError("Cannot instanstiate ZMQ handler with given context", `error`)
      raise Exception("Cannot instanstiate ZMQ handler with given context")
    self.commonLog = Constants.toStringCommon(service)

  '''
    Input - takes a string parameter 'msg' and an integer parameter specifying the logging level as 'severity'
    Logs the msg with the specified logging level.
  '''
  def appendLog (self, msg, severity):
    try:
      with self.queueHandler:
          self.logger.log(severity, self.commonLog+msg)
          print "appende log"
    except Exception as error:
      monitorLog.logError("Failure to append Log: " + msg, `error`)
      raise Exception("Failure to append log: " + msg)

  def appendFailCountLog(self, name, count, severity):
    msg = Constants.toStringCount(name, Constants.FAILCOUNT, count, severity)
    try:
      self.appendLog(msg, severity)
    except Exception as error:
      monitorLog.logError("Failure to append Count Log: " + msg, `error`)
      raise Exception("Failure to append Count log: " + msg)

  def appendCountLog(self, name, count, severity):
    msg = Constants.toStringCount(name, Constants.COUNT, count, severity)
    try:
      self.appendLog(msg, severity)
    except Exception as error:
      monitorLog.logError("Failure append Count Log: " + msg, `error`)
      raise Exception("Failure to append Count log: " + msg)

  def appendTimeLog(self, name, runtime, severity):
    msg = Constants.toStringRuntime(name, Constants.RUNTIME, runtime, severity)
    try:
      self.appendLog(msg, severity)
    except Exception as error:
      monitorLog.logError("Failure to append Count Log: " + msg, `error`)
      raise Exception("Failure to append Count log: " + msg)
 def __init__ (self, service):
   self.handler = Handler(service)
   self.logger = self.handler.getLogHandler()
   # get queue handler for logging
   self.queueHandler = self.handler.getQueueHandler()
   # start queue subscriber for logging 
   self.handler.startQueueSubscriber()
   self.service = service
   self.setHost()
   self.setZone()
   self.setRegion()
   self.commonLog = Constants.toStringCommon(self.region, self.zone, self.host, self.service)
Beispiel #4
0
 def __init__ (self, service, configFile):
   self.service = service
   try:
     self.handler = Handler(self.service, configFile)
     self.logger = self.handler.getLogHandler()
     print "handler returned logger instance"
   except Exception as error:
     monitorLog.logError("Cannot Instantiate Handler with configFile : " + configFile, `error`)
     raise Exception("Cannot Instantiate Handler with configFile : " + configFile)
   ''' Subscriber is now an independent process , hence following lines are commented '''
   # start queue subscriber for logging 
   #self.handler.startQueueSubscriber()
   # get queue handler for logging
   try:
     self.queueHandler = self.handler.getQueueHandler()
   except Exception as error:
     monitorLog.logError("Cannot instanstiate ZMQ handler with given context", `error`)
     raise Exception("Cannot instanstiate ZMQ handler with given context")
   self.commonLog = Constants.toStringCommon(service)