Thomas Waldmann avatar Thomas Waldmann committed 9349041 Draft

update log code (sync with moin 1.9)

move builtin logging_defaults to builtin logging_config

don't give fileConfig a filename, can cause strange misbehaviour

use try/finally

if it used the internal fallback logging config, just tell that as INFO,
not as WARNING

log project, version, code path info on startup

Comments (0)

Files changed (1)

-# Copyright: 2008 MoinMoin:ThomasWaldmann
+# Copyright: 2008-2013 MoinMoin:ThomasWaldmann
 # Copyright: 2007 MoinMoin:JohannesBerg
 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
 
 # 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
 
     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))
     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__)
+    from MoinMoin import project, version
+    l.info('Running {0} {1} code from {2}'.format(project, str(version), code_path))
+
 
 def getLogger(name):
     """ wrapper around logging.getLogger, so we can do some more stuff:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.