changeset 3110:a48929a5036c

logging: make it work correctly by doing logging configuration very early
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 25 Feb 2008 03:41:39 +0100
parents 4cd113328476
children 79f850129782
files MoinMoin/Page.py MoinMoin/config/__init__.py MoinMoin/config/multiconfig.py MoinMoin/conftest.py MoinMoin/events/__init__.py MoinMoin/events/wikidictsrescan.py MoinMoin/failure.py MoinMoin/formatter/__init__.py MoinMoin/i18n/__init__.py MoinMoin/logfile/__init__.py MoinMoin/logfile/editlog.py MoinMoin/parser/text_moin_wiki.py MoinMoin/request/__init__.py MoinMoin/security/antispam.py MoinMoin/security/textcha.py MoinMoin/server/__init__.py MoinMoin/server/server_standalone.py MoinMoin/support/thfcgi.py MoinMoin/util/moinoid.py MoinMoin/wikiutil.py
diffstat 20 files changed, 41 insertions(+), 170 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/Page.py	Mon Feb 25 03:41:39 2008 +0100
@@ -34,7 +34,10 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import os, re, codecs, logging
+import os, re, codecs
+
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import config, caching, user, util, wikiutil
 from MoinMoin.logfile import eventlog
--- a/MoinMoin/config/__init__.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/config/__init__.py	Mon Feb 25 03:41:39 2008 +0100
@@ -8,9 +8,6 @@
 import re
 from MoinMoin import version
 
-# this fix is done here because everyone imports config rather early
-from MoinMoin.support import logging_fix
-
 # unicode: set the char types (upper, lower, digits, spaces)
 from MoinMoin.util.chartypes import *
 
--- a/MoinMoin/config/multiconfig.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/config/multiconfig.py	Mon Feb 25 03:41:39 2008 +0100
@@ -12,11 +12,8 @@
 import sys
 import time
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import config, error, util, wikiutil
 import MoinMoin.auth as authmodule
--- a/MoinMoin/conftest.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/conftest.py	Mon Feb 25 03:41:39 2008 +0100
@@ -19,37 +19,6 @@
 @license: GNU GPL, see COPYING for details.
 """
 
-# here you can configure logging used while running the tests,
-# see http://www.python.org/doc/lib/logging-config-fileformat.html
-logging_defaults = {
-    'loglevel': 'INFO',
-}
-logging_config = """\
-[loggers]
-keys=root
-
-[handlers]
-keys=stderr
-
-[formatters]
-keys=screen
-
-[logger_root]
-level=%(loglevel)s
-handlers=stderr
-
-[handler_stderr]
-class=StreamHandler
-level=NOTSET
-formatter=screen
-args=(sys.stderr, )
-
-[formatter_screen]
-format=%(asctime)s %(name)s %(levelname)s %(message)s
-datefmt=%H%M%S
-class=logging.Formatter
-"""
-
 import atexit
 from inspect import isclass
 from sys import modules
@@ -222,8 +191,6 @@
     Function = MoinTestFunction
 
     def __init__(self, *args, **kwargs):
-        from MoinMoin.server import configureLogging
-        configureLogging(logging_config, logging_defaults)
         self.request = init_test_request()
         super(Module, self).__init__(*args, **kwargs)
 
--- a/MoinMoin/events/__init__.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/events/__init__.py	Mon Feb 25 03:41:39 2008 +0100
@@ -9,11 +9,8 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+log = log.getLogger(__name__)
 
 from MoinMoin import wikiutil
 from MoinMoin.util import pysupport
--- a/MoinMoin/events/wikidictsrescan.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/events/wikidictsrescan.py	Mon Feb 25 03:41:39 2008 +0100
@@ -8,11 +8,8 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import events as ev
 from MoinMoin import wikidicts
--- a/MoinMoin/failure.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/failure.py	Mon Feb 25 03:41:39 2008 +0100
@@ -6,7 +6,10 @@
     @copyright: 2004-2005 Nir Soffer <nirs@freeshell.org>
     @license: GNU GPL, see COPYING for details.
 """
-import sys, os, logging
+import sys, os
+
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin.support import cgitb
 from MoinMoin.error import ConfigurationError
--- a/MoinMoin/formatter/__init__.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/formatter/__init__.py	Mon Feb 25 03:41:39 2008 +0100
@@ -9,11 +9,8 @@
 """
 import re
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin.util import pysupport
 from MoinMoin import wikiutil
--- a/MoinMoin/i18n/__init__.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/i18n/__init__.py	Mon Feb 25 03:41:39 2008 +0100
@@ -27,11 +27,8 @@
 import os, gettext, glob
 from StringIO import StringIO
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import caching
 
--- a/MoinMoin/logfile/__init__.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/logfile/__init__.py	Mon Feb 25 03:41:39 2008 +0100
@@ -8,11 +8,8 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 import os, codecs, errno
 from MoinMoin import config, wikiutil
--- a/MoinMoin/logfile/editlog.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/logfile/editlog.py	Mon Feb 25 03:41:39 2008 +0100
@@ -15,11 +15,8 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin.logfile import LogFile
 from MoinMoin import wikiutil, user, config
--- a/MoinMoin/parser/text_moin_wiki.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/parser/text_moin_wiki.py	Mon Feb 25 03:41:39 2008 +0100
@@ -10,11 +10,8 @@
 
 import re
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import config, wikiutil, macro
 from MoinMoin.Page import Page
--- a/MoinMoin/request/__init__.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/request/__init__.py	Mon Feb 25 03:41:39 2008 +0100
@@ -14,11 +14,8 @@
 proxies_trusted = [] # trust noone!
 #proxies_trusted = ['127.0.0.1', ] # can be a list of multiple IPs
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 def find_remote_addr(addrs):
     """ Find the last remote IP address before it hits our reverse proxies.
--- a/MoinMoin/security/antispam.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/security/antispam.py	Mon Feb 25 03:41:39 2008 +0100
@@ -17,11 +17,8 @@
 except NameError:
     from sets import ImmutableSet as frozenset
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin.security import Permissions
 from MoinMoin import caching, wikiutil
--- a/MoinMoin/security/textcha.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/security/textcha.py	Mon Feb 25 03:41:39 2008 +0100
@@ -24,11 +24,8 @@
 import re
 import random
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import wikiutil
 
--- a/MoinMoin/server/__init__.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/server/__init__.py	Mon Feb 25 03:41:39 2008 +0100
@@ -11,28 +11,11 @@
 import os
 from StringIO import StringIO
 
+from MoinMoin import log
+logging = log.getLogger(__name__)
+
 from MoinMoin import config
 
-import logging as _logging
-from logging.config import fileConfig as _fileConfig
-
-def configureLogging(conf, defaults):
-   _fileConfig(StringIO(conf), defaults)
-
-def getLogger(name):
-    # do we want to strip MoinMoin. from the name?
-    #if name.startswith('MoinMoin.'):
-    #    name = name[9:]
-    logger = _logging.getLogger(name)
-    for levelnumber, levelname in _logging._levelNames.items():
-        if isinstance(levelnumber, int): # that list has also the reverse mapping...
-            setattr(logger, levelname, levelnumber)
-    return logger
-
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
 
 def switchUID(uid, gid):
     """ Switch identity to safe user and group
@@ -74,48 +57,11 @@
     group = None # group ...
     port = None # tcp port number (if supported)
 
-    # Here you can configure the default logging used when running moin,
-    # see http://www.python.org/doc/lib/logging-config-fileformat.html
-    # We just use moin.log in current directory by default, if you want
-    # anything else, override logging_conf in your server script's Config class.
-    logging_defaults = {
-        'logdir': '.',
-        'loglevel': 'INFO',
-}
-    logging_config = """\
-[loggers]
-keys=root
-
-[handlers]
-keys=logfile
-
-[formatters]
-keys=logfile
-
-[logger_root]
-level=%(loglevel)s
-handlers=logfile
-
-[handler_logfile]
-class=FileHandler
-level=NOTSET
-formatter=logfile
-args=('%(logdir)s/moin.log', 'at')
-
-[formatter_logfile]
-format=%(asctime)s %(name)s %(levelname)s %(message)s
-datefmt=
-class=logging.Formatter
-"""
-
     def __init__(self):
         """ Validate and post process configuration values
 
         Will raise RuntimeError for any wrong config value.
         """
-        # First, initialize the logging
-        configureLogging(self.logging_config, self.logging_defaults)
-
         # Check that docs path is accessible
         if self.docs:
             self.docs = os.path.normpath(os.path.abspath(self.docs))
--- a/MoinMoin/server/server_standalone.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/server/server_standalone.py	Mon Feb 25 03:41:39 2008 +0100
@@ -37,11 +37,8 @@
 import os, sys, time, socket, errno, shutil
 import BaseHTTPServer, SimpleHTTPServer, SocketServer
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import version, wikiutil
 from MoinMoin.server import Config, switchUID
--- a/MoinMoin/support/thfcgi.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/support/thfcgi.py	Mon Feb 25 03:41:39 2008 +0100
@@ -35,11 +35,8 @@
 # TODO: Compare compare the number of bytes received on FCGI_STDIN with
 #       CONTENT_LENGTH and abort the update if the two numbers are not equal.
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+import logging
+log = logging.getLogger(__name__)
 
 import os
 import sys
--- a/MoinMoin/util/moinoid.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/util/moinoid.py	Mon Feb 25 03:41:39 2008 +0100
@@ -16,11 +16,8 @@
 
 from MoinMoin import caching
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 # redirect openid logging to moin log
 def log(msg, level=0):
--- a/MoinMoin/wikiutil.py	Sun Feb 24 12:50:54 2008 +0100
+++ b/MoinMoin/wikiutil.py	Mon Feb 25 03:41:39 2008 +0100
@@ -17,11 +17,8 @@
 import time
 import urllib
 
-from MoinMoin.server import getLogger
-logging = getLogger(__name__)
-
-# use this to temporarily and selectively enable debug logging for this module
-#logging.setLevel(logging.DEBUG)
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 from MoinMoin import config
 from MoinMoin.util import pysupport, lock