From 2fec1260c5e150277b7da39a3dfda1fa801273ea Mon Sep 17 00:00:00 2001 From: age Date: Wed, 23 Aug 2006 18:19:37 +0000 Subject: [PATCH] stupid exception --- pythonrewrite/bin2/CryptoBox.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pythonrewrite/bin2/CryptoBox.py b/pythonrewrite/bin2/CryptoBox.py index fcd64f0..cbc7d9d 100755 --- a/pythonrewrite/bin2/CryptoBox.py +++ b/pythonrewrite/bin2/CryptoBox.py @@ -60,7 +60,7 @@ class CryptoBox: format='%(asctime)s %(module)s %(levelname)s %(message)s', stream = sys.stderr) self.log = logging.getLogger("CryptoBox") - self.log.setLevel(logging.WARN) + self.log.setLevel(logging.INFO) self.log.info("loggingsystem is up'n running") ## from now on everything can be logged via self.log... except: @@ -92,11 +92,13 @@ class CryptoBox: sys.exit(1) try: self.cbxPrefs = configobj.ConfigObj(config_file) - self.log.debug("found config: %s" % self.cbxPrefs.items()) - # TODO/RFC: more specific exception handling, please - or (if you want to have fun) just replace the line above with the following: - # self.cbxPrefs = configobj.ConfigObj(obviouslyInvalidVariableName) - except: - self.log.error("Could not read configuration file. I give up.") + if self.cbxPrefs: + self.log.info("found config: %s" % self.cbxPrefs.items()) + else: + FileNotFound = "could not find %s" % config_file + raise FileNotFound + except FileNotFound: + self.log.error(FileNotFound) sys.exit(1) try: nameDB_file = os.path.join( @@ -123,8 +125,9 @@ class CryptoBox: sys.exit(1) try: new_handler = logging.FileHandler(self.cbxPrefs["Log"]["Details"]) + # TODO: loglevel doesn't change after first initialisation new_handler.setLevel(getattr(logging, log_level)) - # this formatter does not work for now + # TODO: this formatter does not work for now new_handler.setFormatter = '%(asctime)s %(module)s %(levelname)s %(message)s' self.log.addHandler(new_handler) except IOError: @@ -157,8 +160,8 @@ class CryptoBox: # this method just demonstrates inheritance effects - may be removed - def cbx_inheritance_test(self): - print "you lucky widow" + def cbx_inheritance_test(self, string="you lucky widow"): + self.log.info(string) # RFC: why should CryptoBoxProps inherit CryptoBox? [l]