changeset 2025:e2a235228c0f

logging: announce moin version, code path. adjust fallback msg logging level. also give more helpful error msg when opening the logging configuration fails.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 03 Mar 2013 02:51:03 +0100
parents 2d11470eb41b
children 54174e49198a
files MoinMoin/log.py
diffstat 1 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/log.py	Sun Mar 03 02:25:21 2013 +0100
+++ b/MoinMoin/log.py	Sun Mar 03 02:51:03 2013 +0100
@@ -61,10 +61,11 @@
 # See http://docs.python.org/library/logging.html#configuring-logging
 # We just use stderr output by default, if you want anything else,
 # you will have to configure logging.
-logging_defaults = {
-    'loglevel': 'INFO',
-}
 logging_config = """\
+[DEFAULT]
+# Default loglevel, to adjust verbosity: DEBUG, INFO, WARNING, ERROR, CRITICAL
+loglevel=INFO
+
 [loggers]
 keys=root
 
@@ -120,7 +121,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 "{0}"'.format(conf_fname))
@@ -130,15 +139,22 @@
     if not configured:
         # load builtin fallback logging config
         from StringIO import StringIO
-        config_file = StringIO(logging_config)
-        logging.config.fileConfig(config_file, logging_defaults)
+        f = StringIO(logging_config)
+        try:
+            logging.config.fileConfig(f)
+        finally:
+            f.close()
         configured = True
         l = getLogger(__name__)
         if err_msg:
             l.warning('load_config for "{0}" failed with "{1}".'.format(conf_fname, err_msg))
-        l.warning('using logging configuration read from built-in fallback in MoinMoin.log module!')
+        l.info('using logging configuration read from built-in fallback in MoinMoin.log module!')
         warnings.showwarning = _log_warning
 
+    import MoinMoin
+    code_path = os.path.dirname(MoinMoin.__file__)
+    l.info('Running %s %s code from %s' % (MoinMoin.project, MoinMoin.version, code_path))
+
 
 def getLogger(name):
     """ wrapper around logging.getLogger, so we can do some more stuff: