def load_config(self, _signal=None, _frame=None): # pylint: disable=unused-argument self.log.debug("Loading JSON config from: %r, signal: %r", self.config_path, _signal) try: new_config = config.read_json_config_file(self.config_path) except (InvalidConfigurationError, subprocess.CalledProcessError, UnicodeDecodeError) as ex: self.log.exception("Invalid config file %r: %s: %s", self.config_path, ex.__class__.__name__, ex) # if we were called by a signal handler we'll ignore (and log) # the error and hope the user fixes the configuration before # restarting pghoard. if _signal is not None: return if isinstance(ex, InvalidConfigurationError): raise raise InvalidConfigurationError(self.config_path) self.config = new_config if self.config.get("syslog") and not self.syslog_handler: self.syslog_handler = logutil.set_syslog_handler( address=self.config.get("syslog_address", "/dev/log"), facility=self.config.get("syslog_facility", "local2"), logger=logging.getLogger(), ) # NOTE: getLevelName() also converts level names to numbers self.log_level = logging.getLevelName(self.config["log_level"]) try: logging.getLogger().setLevel(self.log_level) except ValueError: self.log.exception("Problem with log_level: %r", self.log_level) # statsd settings may have changed stats = self.config.get("statsd", {}) self.stats = statsd.StatsClient(host=stats.get("host"), port=stats.get("port"), tags=stats.get("tags"), message_format=stats.get("format")) self.log.debug("Loaded config: %r from: %r", self.config, self.config_path)
def load_config(self, _signal=None, _frame=None): # pylint: disable=unused-argument self.log.debug("Loading JSON config from: %r, signal: %r", self.config_path, _signal) try: new_config = config.read_json_config_file(self.config_path) except (InvalidConfigurationError, subprocess.CalledProcessError, UnicodeDecodeError) as ex: self.log.exception("Invalid config file %r: %s: %s", self.config_path, ex.__class__.__name__, ex) # if we were called by a signal handler we'll ignore (and log) # the error and hope the user fixes the configuration before # restarting pghoard. if _signal is not None: return if isinstance(ex, InvalidConfigurationError): raise raise InvalidConfigurationError(self.config_path) self.config = new_config if self.config.get("syslog") and not self.syslog_handler: self.syslog_handler = logutil.set_syslog_handler( address=self.config.get("syslog_address", "/dev/log"), facility=self.config.get("syslog_facility", "local2"), logger=logging.getLogger(), ) # NOTE: getLevelName() also converts level names to numbers self.log_level = logging.getLevelName(self.config["log_level"]) try: logging.getLogger().setLevel(self.log_level) except ValueError: self.log.exception("Problem with log_level: %r", self.log_level) # statsd settings may have changed stats = self.config.get("statsd", {}) self.stats = statsd.StatsClient(host=stats.get("host"), port=stats.get("port"), tags=stats.get("tags"), message_format=stats.get("format")) self.log.debug("Loaded config: %r from: %r", self.config, self.config_path)
def load_config(self, _signal=None, _frame=None): # pylint: disable=unused-argument self.log.debug("Loading JSON config from: %r, signal: %r", self.config_path, _signal) try: new_config = config.read_json_config_file(self.config_path) except (InvalidConfigurationError, subprocess.CalledProcessError, UnicodeDecodeError) as ex: self.log.exception("Invalid config file %r: %s: %s", self.config_path, ex.__class__.__name__, ex) # if we were called by a signal handler we'll ignore (and log) # the error and hope the user fixes the configuration before # restarting pghoard. if _signal is not None: return if isinstance(ex, InvalidConfigurationError): raise raise InvalidConfigurationError(self.config_path) # clear this objects site transfer storage config self.site_transfers = {} self.config = new_config if self.config.get("syslog") and not self.syslog_handler: self.syslog_handler = logutil.set_syslog_handler( address=self.config.get("syslog_address", "/dev/log"), facility=self.config.get("syslog_facility", "local2"), logger=logging.getLogger(), ) # NOTE: getLevelName() also converts level names to numbers self.log_level = logging.getLevelName(self.config["log_level"]) try: logging.getLogger().setLevel(self.log_level) except ValueError: self.log.exception("Problem with log_level: %r", self.log_level) # Setup monitoring clients self.metrics = metrics.Metrics( statsd=self.config.get("statsd", None), pushgateway=self.config.get("pushgateway", None), prometheus=self.config.get("prometheus", None)) # need to refresh the web server config too if hasattr(self, "webserver") and hasattr(self.webserver, "server"): self.webserver.server.config = new_config for thread in self._get_all_threads(): thread.config = new_config thread.site_transfers = {} self.log.debug("Loaded config: %r from: %r", self.config, self.config_path)
def load_config(self, _signal=None, _frame=None): # pylint: disable=unused-argument self.log.debug("Loading JSON config from: %r, signal: %r", self.config_path, _signal) try: new_config = config.read_json_config_file(self.config_path) except (InvalidConfigurationError, subprocess.CalledProcessError, UnicodeDecodeError) as ex: self.log.exception("Invalid config file %r: %s: %s", self.config_path, ex.__class__.__name__, ex) # if we were called by a signal handler we'll ignore (and log) # the error and hope the user fixes the configuration before # restarting pghoard. if _signal is not None: return if isinstance(ex, InvalidConfigurationError): raise raise InvalidConfigurationError(self.config_path) self.config = new_config if self.config.get("syslog") and not self.syslog_handler: self.syslog_handler = logutil.set_syslog_handler( address=self.config.get("syslog_address", "/dev/log"), facility=self.config.get("syslog_facility", "local2"), logger=logging.getLogger(), ) # NOTE: getLevelName() also converts level names to numbers self.log_level = logging.getLevelName(self.config["log_level"]) try: logging.getLogger().setLevel(self.log_level) except ValueError: self.log.exception("Problem with log_level: %r", self.log_level) # Setup monitoring clients self.metrics = metrics.Metrics( statsd=self.config.get("statsd", None), pushgateway=self.config.get("pushgateway", None), prometheus=self.config.get("prometheus", None)) for thread in self._get_all_threads(): thread.config = new_config thread.site_transfers = {} self.log.debug("Loaded config: %r from: %r", self.config, self.config_path)