Beispiel #1
0
 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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 def __init__ (self, service, configFile):
   try:
     print "logger instantiated"
     self.logHandler = LogHandler(service, configFile)
   except Exception as error:
     monitorLog.logError("Cannot Instantiate Logger with configFile : " + configFile, `error`)
     raise IncorrectConfigException("Cannot Instantiate Logger with configFile : " + configFile)
   self.threadLocal = threading.local()
   self.counter = 0;
Beispiel #5
0
 def reportLatency (self, name, action, severity = 20, *args, **kwargs):
   self.startTime()
   try:
     actualReturn = action(*args, **kwargs)
   except Exception as error:
     monitorLog.logError("Failed Action " + `action`, `error`)
     raise Exception("Failed Action :" + `action`)
   self.reportTime(name, severity)
   return actualReturn
Beispiel #6
0
 def logIfFail (self, name, expectedReturn, counter, action, severity = 20, *args, **kwargs):
   count = self.reportCountNE(expectedReturn, counter, action, *args, **kwargs)
   if count > 0:
     try:
       print "logging failure"
       self.logHandler.appendFailCountLog(name, count, severity)	
     except Exception as error:
       monitorLog.logError("Failed to append log for metric: " + name, `error`)
       raise LoggingException("Failed to append log for metric: " + name)
   return count
Beispiel #7
0
 def reportTime (self, name, severity = 20):
   endTime = time.time()
   runTime = endTime - self.threadLocal.startTime
   try:
     if runTime >= Logger.threshold_latency:
       self.logHandler.appendTimeLog(name, runTime, 'CRITICAL')
     self.logHandler.appendTimeLog(name, runTime, severity)
   except Exception as error:
     monitorLog.logError("Failed to append log for metric: " + name, `error`)
     raise LoggingException("Failed to append log for metric: " + name)
Beispiel #8
0
 def logCount (self, name, counter, severity = 20):
   if counter > 0:
     try:
       if counter >= Logger.threshold_count:
         self.logHandler.appendCountLog(name, counter,  'CRITICAL')
       self.logHandler.appendCountLog(name, counter, severity)
     except Exception as error:
       monitorLog.logError("Failed to append log for metric: " + name, `error`)
       raise LoggingException("Failed to append log for metric: " + name)
     return 1
   return 0
Beispiel #9
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)