[Zconfig] SVN: ZConfig/trunk/ add tested documentation for configureLoggers.

Chris Withers chris at simplistix.co.uk
Thu Jun 11 05:57:44 EDT 2009


Log message for revision 100855:
  add tested documentation for configureLoggers.

Changed:
  U   ZConfig/trunk/README.txt
  A   ZConfig/trunk/ZConfig/tests/test_readme.py

-=-
Modified: ZConfig/trunk/README.txt
===================================================================
--- ZConfig/trunk/README.txt	2009-06-11 09:41:00 UTC (rev 100854)
+++ ZConfig/trunk/README.txt	2009-06-11 09:57:44 UTC (rev 100855)
@@ -23,6 +23,36 @@
 
 Reference documentation is available in the doc/ directory.
 
+One common use of ZConfig is to configure the Python logging
+framework. This is extremely simple to do as the following example
+demonstrates:
+
+    >>> from ZConfig import configureLoggers
+    >>> configureLoggers('''
+    ... <logger>
+    ...    level INFO
+    ...    <logfile>
+    ...       PATH STDOUT
+    ...       format %(levelname)s %(name)s %(message)s
+    ...    </logfile>
+    ... </logger>
+    ... ''')
+
+The above configures the root logger to output messages logged at INFO
+or above to the console, as we can see in the following example:
+
+    >>> from logging import getLogger
+    >>> logger = getLogger()
+    >>> logger.info('An info message')
+    INFO root An info message
+    >>> logger.debug('A debug message')
+
+A more common configuration would see STDOUT replaced with a path to
+the file into which log entries would be written.
+
+For more information, see section 5.2 on the ZConfig documentation and
+the examples in ZConfig/components/logger/tests.
+
 Information on the latest released version of the ZConfig package is
 available at
 

Added: ZConfig/trunk/ZConfig/tests/test_readme.py
===================================================================
--- ZConfig/trunk/ZConfig/tests/test_readme.py	                        (rev 0)
+++ ZConfig/trunk/ZConfig/tests/test_readme.py	2009-06-11 09:57:44 UTC (rev 100855)
@@ -0,0 +1,34 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import logging,os,unittest
+from zope.testing.doctest import DocFileSuite, REPORT_NDIFF,ELLIPSIS
+
+options = REPORT_NDIFF|ELLIPSIS
+
+old = {}
+def setUp(test):
+    global old
+    logger=logging.getLogger()
+    old['level']=logger.level
+    old['handlers'] = logger.handlers[:]
+
+def tearDown(test):
+    logger = logging.getLogger()
+    logger.level = old['level']
+    logger.handlers = old['handlers']
+
+def test_suite():
+    return unittest.TestSuite((
+        DocFileSuite('../../readme.txt', optionflags=options),
+        ))


Property changes on: ZConfig/trunk/ZConfig/tests/test_readme.py
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the ZConfig mailing list