Пример #1
0
    def __init__(self, config, handlers, formatters={}):
        self.node_id = config.getVal('device.node_id')
        self.target = config.getVal('device.target', "none")

        # Build config dict to initialise
        # Ensure all handlers don't drop logs based on severity level
        for h in handlers:
            handlers[h]["level"] = "NOTSET"

        logconfig = {
            "version": 1,
            "formatters": formatters,
            "handlers": handlers,
            # initialise all defined logger handlers
            "loggers": {
                self.node_id: {
                    "handlers": handlers.keys()
                }
            }
        }

        try:
            logging.config.dictConfig(logconfig)
        except Exception as e:
            print >> sys.stderr, "Invalid logging config"
            print type(e)
            print e
            exit(1)

        self.logger = logging.getLogger(self.node_id)
Пример #2
0
    def __init__(self, config, handlers, formatters={}):
        self.node_id = config.getVal('device.node_id')

        # Build config dict to initialise
        # Ensure all handlers don't drop logs based on severity level
        for h in handlers:
            handlers[h]["level"] = "NOTSET"

        logconfig = {
            "version": 1,
            "formatters": formatters,
            "handlers": handlers,
            # initialise all defined logger handlers
            "loggers": {
                self.node_id: {
                    "handlers": handlers.keys()
                }
            }
        }

        try:
            logging.config.dictConfig(logconfig)
        except Exception as e:
            print("Invalid logging config", file=sys.stderr)
            print(type(e))
            print(e)
            exit(1)

        # Check if ignorelist is populated
        self.ignorelist = config.getVal('ip.ignorelist', default='')

        self.logger = logging.getLogger(self.node_id)
Пример #3
0
def getLogger(config):
    try:
        d = config.getVal('logger')
    except Exception as e:
        print("Error: config does not have 'logger' section", file=sys.stderr)
        exit(1)

    classname = d.get('class', None)
    if classname is None:
        print("Logger section is missing the class key.", file=sys.stderr)
        exit(1)

    LoggerClass = globals().get(classname, None)
    if LoggerClass is None:
        print("Logger class (%s) is not defined." % classname, file=sys.stderr)
        exit(1)

    kwargs = d.get('kwargs', None)
    if kwargs is None:
        print("Logger section is missing the kwargs key.", file=sys.stderr)
        exit(1)
    try:
        logger = LoggerClass(config, **kwargs)
    except Exception as e:
        print("An error occured initialising the logger class",
              file=sys.stderr)
        print(e)
        exit(1)

    return logger
Пример #4
0
def getLogger(config):
    try:
        d = config.getVal('logger')
    except Exception as e:
        print >> sys.stderr, "Error: config does not have 'logger' section"
        exit(1)

    classname = d.get('class', None)
    if classname is None:
        print >> sys.stderr, "Logger section is missing the class key."
        exit(1)

    LoggerClass = globals().get(classname, None)
    if LoggerClass is None:
        print >> sys.stderr, "Logger class (%s) is not defined." % classname
        exit(1)

    kwargs = d.get('kwargs', None)
    if kwargs is None:
        print >> sys.stderr, "Logger section is missing the kwargs key."
        exit(1)

    try:
        logger = LoggerClass(config, **kwargs)
    except Exception as e:
        print >> sys.stderr, "An error occured initialising the logger class"
        print e
        exit(1)

    return logger
Пример #5
0
    def __init__(self, config, handlers, formatters={}):
        self.node_id = config.getVal('device.node_id')

        # Build config dict to initialise
        # Ensure all handlers don't drop logs based on severity level
        for h in handlers:
            handlers[h]["level"] = "NOTSET"

        logconfig = {
            "version": 1,
            "formatters" : formatters,
            "handlers": handlers,
            # initialise all defined logger handlers
            "loggers": {
                self.node_id : {
                    "handlers": handlers.keys()
                }
            }
        }

        try:
            logging.config.dictConfig(logconfig)
        except Exception as e:
            print >> sys.stderr, "Invalid logging config"
            print type(e)
            print e
            exit(1)

        self.logger = logging.getLogger(self.node_id)
Пример #6
0
    def __init__(self, config, handlers, formatters={}):
        self.node_id = config.getVal('device.node_id')
        try:
            self.host_ip = config.getVal('host.ip')
        except Exception as e:
            print("Error: config does not have 'host.ip' parameter",
                  file=sys.stderr)
            exit(1)
        try:
            self.whitelist = config.getVal('whitelist')
            print("Whitelist Found")
            for ip in self.whitelist:
                print(ip + "\n")
        except Exception as e:
            print("Error: Config does not have 'whitelist' parameter",
                  file=sys.strerr)
            exit(1)

        # Build config dict to initialise
        # Ensure all handlers don't drop logs based on severity level
        for h in handlers:
            handlers[h]["level"] = "NOTSET"

        logconfig = {
            "version": 1,
            "formatters": formatters,
            "handlers": handlers,
            # initialise all defined logger handlers
            "loggers": {
                self.node_id: {
                    "handlers": handlers.keys()
                }
            }
        }

        try:
            logging.config.dictConfig(logconfig)
        except Exception as e:
            print("Invalid logging config", file=sys.stderr)
            print(type(e))
            print(e)
            exit(1)

        self.logger = logging.getLogger(self.node_id)