def __init__(self, jobId, useTestApi = False): #Log ID self.logId = -1 self.useTestApi = useTestApi # Prepare SQL query to INSERT a Log record into the database. sqlLog = "INSERT INTO sensorLog(jobId) VALUES(%s)" % (jobId) self._connect() try: # Execute the SQL command self.cursor.execute(sqlLog) self.logId = self.cursor.lastrowid # Commit your changes in the database self.db.commit() if( self.logId > 0): self._logAllSensors() except Exception as e: # Rollback in case there is any error #print "Error!" lib = libStatLogger.statLogger() lib.logError( e ) print e self.db.rollback() # disconnect from server self._dissconnect()
def testlibStatLogger(self): error = "" lib = libStatLogger.statLogger() try: lib.logEntry("TEST Info") lib.logError("TEST Error") except: error = "Can not log to database" self.showResult(error)
def _logSensor(self, sensorId, value): # Prepare SQL query to INSERT all sensors into the database. sqlItem = "INSERT INTO sensorValue (logId, sensorId, value) VALUES ( %s, %s, %s )" try: self.cursor.execute(sqlItem % (self.logId, sensorId, value) ) except: ErrStr = "ERR - could not log sensor value for %s with value %s" % (sensorId, value) lib = libStatLogger.statLogger() lib.logError( ErrStr ) print ErrStr