Exemple #1
0
    def reload_config(self):
        logger.debug("Reloading config from " + str(self.config_file))
        config = read_config(self.config_file)
        for key, val in config.iteritems():
            # checking for new options in proc
            if key in self.procs_config:
                identical = True
                for key_item, val_item in config[key].iteritems():
                    if(key_item not in self.procs_config[key] or \
                           (self.procs_config[key][key_item] != val_item)):
                        identical = False
                        break
                # checking from deletion of options in proc
                for key_item in self.procs_config[key]:
                    if key_item not in config[key]:
                        identical = False
                        break
                if not identical:
                    # FIXME: a reload might suffice…
                    self.kill(key)
                    pid = self.spawn(key, val)
                    if pid:
                        logger.debug("Updated %s as pid %d", str(key), pid)
                    else:
                        logger.error("Couldn't update " + str(key))
            else:
                pid = self.spawn(key, val)
                if pid:
                    logger.debug("Added %s as pid %d", str(key), pid)

        for key in set(self.procs_config.keys()) - set(config.keys()):
            self.kill(key)
            del self.procs_config[key]
            logger.debug("Removed " + str(key))
        self.procs_config = config
Exemple #2
0
    def reload_config(self):
        logger.debug("Reloading config from " + str(self.config_file))
        config = read_config(self.config_file)
        for key, val in config.iteritems():
            # checking for new options in proc
            if key in self.procs_config:
                identical = True
                for key_item, val_item in config[key].iteritems():
                    if(key_item not in self.procs_config[key] or \
                           (self.procs_config[key][key_item] != val_item)):
                        identical = False
                        break
                # checking from deletion of options in proc
                for key_item in self.procs_config[key]:
                    if key_item not in config[key]:
                        identical = False
                        break
                if not identical:
                    # FIXME: a reload might suffice…
                    self.kill(key)
                    pid = self.spawn(key, val)
                    if pid:
                        logger.debug("Updated %s as pid %d", str(key), pid)
                    else:
                        logger.error("Couldn't update " + str(key))
            else:
                pid = self.spawn(key, val)
                if pid:
                    logger.debug("Added %s as pid %d", str(key), pid)

        for key in set(self.procs_config.keys()) - set(config.keys()):
            self.kill(key)
            del self.procs_config[key]
            logger.debug("Removed " + str(key))
        self. procs_config = config
def add_time_2_log_filename(config):
    for k, v in config.iteritems():
        if k == 'filename':
            config[k] = v + "." + time.strftime("%Y-%d-%m-%s")
            print('log file name: %s' % config[k])
        elif type(v) is dict:
            add_time_2_log_filename(v)
Exemple #4
0
 def _load_hooks(self, config):
     self['loaded_hooks'] = []
     for module_name, options in config.iteritems():
         try:
             module = import_module('hooks.%s' % (module_name, ))
         except ImportError as err:
             logger.error('unable to load module %s: %s' % (module_name, err))
         else:
             for obj_name, obj in getmembers(module):
                 if isclass(obj) and getattr(obj, 'hook_name', None) == module_name:
                     self['loaded_hooks'].append(obj(**options))
Exemple #5
0
def _post_json_config(config):
    logger.debug('start: config: %s', config)
    for k, v in config.iteritems():
        if v.__class__.__name__ != 'str':
            continue

        orig_v = v
        try:
            config[k] = json.loads(v)
        except:
            config[k] = orig_v

    logger.debug('end: config: %s', config)
Exemple #6
0
def _post_json_config(config):
    logger.debug('start: config: %s', config)
    for k, v in config.iteritems():
        if v.__class__.__name__ != 'str':
            continue

        orig_v = v
        try:
            config[k] = json.loads(v)
        except:
            config[k] = orig_v

    logger.debug('end: config: %s', config)
Exemple #7
0
def _post_json_config(config):
    '''
    try to do json load on value
    '''
    for k, v in config.iteritems():
        if v.__class__.__name__ != 'str':
            continue

        orig_v = v
        try:
            config[k] = json.loads(v)
        except:
            config[k] = orig_v
Exemple #8
0
 def _load_hooks(self, config):
     self['loaded_hooks'] = []
     for module_name, options in config.iteritems():
         try:
             module = import_module('hooks.%s' % (module_name, ))
         except ImportError as err:
             logger.error('unable to load module %s: %s' %
                          (module_name, err))
         else:
             for obj_name, obj in getmembers(module):
                 if isclass(obj) and getattr(obj, 'hook_name',
                                             None) == module_name:
                     self['loaded_hooks'].append(obj(**options))
Exemple #9
0
def _post_json_config(config):
    '''
    try to do json load on value
    '''
    for k, v in config.iteritems():
        if v.__class__.__name__ != 'str':
            continue

        orig_v = v
        try:
            config[k] = json.loads(v)
        except:
            config[k] = orig_v
Exemple #10
0
def initlog(config, console=False, backup_count=0, separate=True):
    conf = {
        "version": 1,
        "formatters": {
            "myformat": {
                "format": "%(asctime)s %(process)d,%(threadName)s %(filename)s:%(lineno)d [%(levelname)s] %(message)s"
            }
        },
        "filters": {
            "debug": {"()": "logger.SingleLevelFilter", "passlevel": logging.DEBUG},
            "info": {"()": "logger.SingleLevelFilter", "passlevel": logging.INFO},
            "note": {"()": "logger.SingleLevelFilter", "passlevel": logging.NOTE},
            "mpay": {"()": "logger.SingleLevelFilter", "passlevel": logging.MPAY},
            "risk": {"()": "logger.SingleLevelFilter", "passlevel": logging.RISK},
            "warn": {"()": "logger.SingleLevelFilter", "passlevel": logging.WARN},
            "error": {"()": "logger.SingleLevelFilter", "passlevel": logging.ERROR},
            "critical": {"()": "logger.SingleLevelFilter", "passlevel": logging.CRITICAL},
        },
        "handlers": {
            "console": {
                "class": "logger.ScreenHandler",
                "formatter": "myformat",
                "level": "DEBUG",
                "stream": "ext://sys.stdout",
            }
        },
        "root": {"level": "DEBUG"},
    }

    handlers = ["console"] if console else []
    for level, name in config.iteritems():
        handler = "%s_FILE" % level
        handlers.append(handler)
        conf["handlers"][handler] = {
            "class": "logger.MyTimedRotatingFileHandler",
            "filename": name,
            "when": "midnight",
            "interval": 1,
            "formatter": "myformat",
            "level": level.upper(),
            "backupCount": backup_count,
            "filters": [level.lower()] if separate else None,
        }

    conf["root"].update({"handlers": handlers})
    logging.config.dictConfig(conf)
    return logging.getLogger()
Exemple #11
0
def initlog(config, console=False, backup_count=0, separate=True):
    conf = {
        'version': 1,
        'formatters': {
            'myformat': {
                'format':
                '%(asctime)s %(process)d,%(threadName)s %(filename)s:%(lineno)d [%(levelname)s] %(message)s'
            }
        },
        'filters': {
            'debug': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.DEBUG
            },
            'info': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.INFO
            },
            'note': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.NOTE
            },
            'mpay': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.MPAY
            },
            'risk': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.RISK
            },
            'warn': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.WARN
            },
            'error': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.ERROR
            },
            'critical': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.CRITICAL
            }
        },
        'handlers': {
            'console': {
                'class': 'util.logger.ScreenHandler',
                'formatter': 'myformat',
                'level': 'DEBUG',
                'stream': 'ext://sys.stdout'
            }
        },
        'root': {
            'level': 'DEBUG'
        }
    }

    handlers = ['console'] if console else []
    for level, name in config.iteritems():
        handler = '%s_FILE' % level
        handlers.append(handler)
        conf['handlers'][handler] = {
            'class': 'util.logger.MyTimedRotatingFileHandler',
            'filename': name,
            'when': 'midnight',
            'interval': 1,
            'formatter': 'myformat',
            'level': level.upper(),
            'backupCount': backup_count,
            'filters': [level.lower()] if separate else None
        }

    conf['root'].update({'handlers': handlers})
    logging.config.dictConfig(conf)
    return logging.getLogger()
Exemple #12
0
def initlog(config, console=False, backup_count=0, separate=True):
    conf = {
        'version': 1,
        'formatters': {
            'myformat': {
                'format': '%(asctime)s %(process)d,%(threadName)s %(filename)s:%(lineno)d [%(levelname)s] %(message)s'
            }
        },
        'filters': {
            'debug': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.DEBUG
            },
            'info': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.INFO
            },
            'note': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.NOTE
            },
            'mpay': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.MPAY
            },
            'risk': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.RISK
            },
            'warn': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.WARN
            },
            'error': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.ERROR
            },
            'critical': {
                '()': 'util.logger.SingleLevelFilter',
                'passlevel': logging.CRITICAL
            }
        },
        'handlers': {
            'console': {
                'class': 'util.logger.ScreenHandler',
                'formatter': 'myformat',
                'level': 'DEBUG',
                'stream': 'ext://sys.stdout'
            }
        },
        'root': {
            'level': 'DEBUG'
        }
    }

    handlers = ['console'] if console else []
    for level, name in config.iteritems():
        handler = '%s_FILE' % level
        handlers.append(handler)
        conf['handlers'][handler] = {
            'class': 'util.logger.MyTimedRotatingFileHandler',
            'filename': name,
            'when': 'midnight',
            'interval': 1,
            'formatter': 'myformat',
            'level': level.upper(),
            'backupCount': backup_count,
            'filters': [level.lower()] if separate else None
        }

    conf['root'].update({'handlers': handlers})
    logging.config.dictConfig(conf)
    return logging.getLogger()