import logging import logging.handlers import datetime class ISEE_Logger(object): __logger = None __logHandler = None __formater = None __logHandlerConsole = None def __init__(self, level=logging.INFO): # Create syslog logger self.__logger = logging.getLogger('ISEE_logger') self.__logger.setLevel(level) self.__logHandler = logging.handlers.SysLogHandler('/dev/log') self.__logHandlerConsole = logging.StreamHandler() self.__formater = logging.Formatter('Python: { "loggerName":"%(name)s", "timestamp":"%(asctime)s", "pathName":"%(pathname)s", "logRecordCreationTime":"%(created)f", "functionName":"%(funcName)s", "levelNo":"%(levelno)s", "lineNo":"%(lineno)d", "time":"%(msecs)d", "levelName":"%(levelname)s", "message":"%(message)s"}') self.__logHandler.formatter = self.__formater self.__logHandlerConsole.formatter = self.__formater self.__logger.addHandler(self.__logHandler) self.__logger.addHandler(self.__logHandlerConsole) def setLogLevel(self, level): if level.upper() == "DEBUG": nlevel = logging.DEBUG elif level.upper() == "INFO": nlevel = logging.INFO elif level.upper() == "ERROR": nlevel = logging.ERROR elif level.upper() == "WARNING": nlevel = logging.WARNING else: nlevel = logging.DEBUG self.__logger.setLevel(nlevel) def getlogger(self): return self.__logger class MeasureTime: __difference = None __first_time = None __later_time = None def __init__(self): self.__first_time = datetime.datetime.now() def start(self): self.first_time = datetime.datetime.now() def stop(self): self.__later_time = datetime.datetime.now() self.__difference = self.__later_time - self.__first_time return self.__difference.total_seconds() def getTime(self): return self.__difference.total_seconds() global logObj logObj = ISEE_Logger(logging.INFO)