diff MoinMoin/log.py @ 5916:881d9053592a

logging: if the logging config file can't be read, give a helpful error msg
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 16 Jan 2013 16:16:42 +0100
parents 124c1919133d
children c14974df2b58
line wrap: on
line diff
--- a/MoinMoin/log.py	Tue Jan 08 00:07:30 2013 +0100
+++ b/MoinMoin/log.py	Wed Jan 16 16:16:42 2013 +0100
@@ -120,7 +120,15 @@
     if conf_fname:
         try:
             conf_fname = os.path.abspath(conf_fname)
-            logging.config.fileConfig(conf_fname)
+            # we open the conf file here to be able to give a reasonable
+            # error message in case of failure (if we give the filename to
+            # fileConfig(), it silently ignores unreadable files and gives
+            # unhelpful error msgs like "No section: 'formatters'"):
+            f = open(conf_fname)
+            try:
+                logging.config.fileConfig(f)
+            finally:
+                f.close()
             configured = True
             l = getLogger(__name__)
             l.info('using logging configuration read from "%s"' % conf_fname)