diff MoinMoin/conftest.py @ 3105:80e1a910a2f1

make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 21:43:47 +0100
parents 96319d867986
children c6e39279f83b
line wrap: on
line diff
--- a/MoinMoin/conftest.py	Sat Feb 23 16:14:04 2008 +0100
+++ b/MoinMoin/conftest.py	Sat Feb 23 21:43:47 2008 +0100
@@ -19,11 +19,41 @@
 @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': 'DEBUG',
+}
+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
 import sys
-import logging
 
 import py
 
@@ -87,23 +117,6 @@
     return request
 
 
-def init_test_logging(loglevel_stderr=logging.DEBUG):
-    """ initialize python stdlib logging framework to output stuff to stderr """
-    logger = logging.getLogger('') # root logger
-    logger.setLevel(logging.NOTSET) # otherwise it has WARNING by default!
-
-    # define a Handler which writes to sys.stderr
-    logstderr = logging.StreamHandler()
-    logstderr.setLevel(loglevel_stderr)
-    # set a format which is simpler for console use
-    formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%H%M%S')
-    # tell the handler to use this format
-    logstderr.setFormatter(formatter)
-    # add the handler to the root logger
-    logger.addHandler(logstderr)
-
-    logging.info("logging initialized")
-
 class TestConfig:
     """ Custom configuration for unit tests
 
@@ -209,7 +222,8 @@
     Function = MoinTestFunction
 
     def __init__(self, *args, **kwargs):
-        init_test_logging()
+        from MoinMoin.server import configureLogging
+        configureLogging(logging_config, logging_defaults)
         self.request = init_test_request()
         super(Module, self).__init__(*args, **kwargs)