summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/iseelogger.py
blob: 785a78cfb6a1cabc5260757eae0e1f962c60a4ce (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
import logging
import logging.handlers


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