summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/iseelogger.py
blob: 4b1087cf672af490d4480013a45b4cbf3e27cafa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)