diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-03 17:01:18 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-03 17:01:18 +0100 |
commit | a955fa4c56e55767f21fbde68c56f122e2104ccd (patch) | |
tree | e8a5263d5fc179693472bddac6e29ecafabf6723 /lorrycontroller | |
parent | fb032af65309be0770cc5b75e1730123ad6f3734 (diff) | |
download | lorry-controller-a955fa4c56e55767f21fbde68c56f122e2104ccd.tar.gz |
Better logging levels
Diffstat (limited to 'lorrycontroller')
-rw-r--r-- | lorrycontroller/confparser.py | 34 | ||||
-rw-r--r-- | lorrycontroller/workingstate.py | 12 |
2 files changed, 26 insertions, 20 deletions
diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py index b78dc54..188ac6b 100644 --- a/lorrycontroller/confparser.py +++ b/lorrycontroller/confparser.py @@ -34,12 +34,16 @@ class LorryControllerConfig(object): self.duetimes = {} self.troves = [] confpath = os.path.join(app.settings['work-area'], confpath) - logging.debug("Parsing configuration: %s" % confpath) - with open(confpath, "r") as fh: - self._raw_conf = json.load(fh) + logging.info("Parsing configuration: %s" % confpath) + try: + with open(confpath, "r") as fh: + self._raw_conf = json.load(fh) + except Exception, e: + logging.error("Unable to parse: %r" % e) + raise logging.debug("Validating configuration semantics") self._validate__raw_conf() - logging.debug("Configuration loaded") + logging.info("Configuration loaded") def _validate__raw_conf(self): '''Validate the entire raw config.''' @@ -127,16 +131,16 @@ class LorryControllerConfig(object): try: with open(lorry, "r") as fh: lorry_json = json.load(fh) - for name, content in lorry_json.iteritems(): - fullname = os.path.join(entry['prefix'], name) - if self.lorries.get(fullname, None) is not None: - self._give_up("Lorry repeated: %s" % fullname) - content['controller-uuid'] = entry['uuid'] - my_lorry_names.add(fullname) - self.lorries[fullname] = content + for name, content in lorry_json.iteritems(): + fullname = os.path.join(entry['prefix'], name) + if self.lorries.get(fullname, None) is not None: + self._give_up("Lorry repeated: %s" % fullname) + content['controller-uuid'] = entry['uuid'] + my_lorry_names.add(fullname) + self.lorries[fullname] = content except Exception, e: - logging.debug("Unable to parse %s, because of %s. Moving on" % - (lorry, e)) + logging.warning("Unable to parse %s, because of %s. " + "Moving on" % (lorry, e)) # Now calculate the 'next due' time for every lorry we just parsed starttime = time.time() - 1 @@ -180,8 +184,8 @@ class LorryControllerConfig(object): self.troves.append(entry) def update_trove(self, trove, state): - logging.debug("Processing trove %s (%s)" % (trove['trovehost'], - trove['uuid'])) + logging.info("Processing trove %s (%s)" % (trove['trovehost'], + trove['uuid'])) # 1. Ensure that if we need to 'ls' the trove, we do it now = time.time() listcmdargs = ["ssh", "-oStrictHostKeyChecking=no", diff --git a/lorrycontroller/workingstate.py b/lorrycontroller/workingstate.py index 68d2ef9..f6f8128 100644 --- a/lorrycontroller/workingstate.py +++ b/lorrycontroller/workingstate.py @@ -34,7 +34,7 @@ class LorryFileRunner(object): cmdargs.append(self.lorryfile) exit, out, err = self.mgr.app.maybe_runcmd(cmdargs) if exit == 0: - logging.info("Lorry of %s succeeded: %s" % (self.lorryname, out)) + logging.debug("Lorry of %s succeeded: %s" % (self.lorryname, out)) else: logging.warn("Lorry of %s failed: %s" % (self.lorryname, err)) @@ -61,7 +61,8 @@ class WorkingStateManager(object): self.trove_state_file = os.path.join(self.workdir, "last-trove-state.json") if os.path.exists(self.lorry_state_file): - logging.debug("Loading state file: %s" % self.lorry_state_file) + logging.info("Loading lorry state file: %s" % + self.lorry_state_file) with open(self.lorry_state_file, "r") as fh: self.lorry_state = json.load(fh) for lorry_name, dct in self.lorry_state.iteritems(): @@ -71,18 +72,19 @@ class WorkingStateManager(object): self.lorry_state = dict() if os.path.exists(self.trove_state_file): - logging.debug("Loading state file: %s" % self.trove_state_file) + logging.info("Loading trove state file: %s" % + self.trove_state_file) with open(self.trove_state_file, "r") as fh: self.trove_state = json.load(fh) else: self.trove_state = dict() def save_state(self): - logging.debug("Serialising state: %s" % self.lorry_state_file) + logging.info("Serialising lorry state: %s" % self.lorry_state_file) with open(self.lorry_state_file, "w") as fh: json.dump(self.lorry_state, fh, sort_keys=True, indent=4) fh.write("\n") - logging.debug("Serialising state: %s" % self.trove_state_file) + logging.info("Serialising trove state: %s" % self.trove_state_file) with open(self.trove_state_file, "w") as fh: json.dump(self.trove_state, fh, sort_keys=True, indent=4) fh.write("\n") |