[Python-checkins] r42117 - python/trunk/Lib/logging/config.py

vinay.sajip python-checkins at python.org
Fri Jan 20 19:28:04 CET 2006


Author: vinay.sajip
Date: Fri Jan 20 19:28:03 2006
New Revision: 42117

Modified:
   python/trunk/Lib/logging/config.py
Log:
Added the ability to specify a class attribute in Formatter configuration. Contributed by Shane Hathaway.

Modified: python/trunk/Lib/logging/config.py
==============================================================================
--- python/trunk/Lib/logging/config.py	(original)
+++ python/trunk/Lib/logging/config.py	Fri Jan 20 19:28:03 2006
@@ -86,6 +86,21 @@
         logging._releaseLock()
 
 
+def _resolve(name):
+    """Resolve a dotted name to a global object."""
+    name = string.split(name, '.')
+    used = name.pop(0)
+    found = __import__(used)
+    for n in name:
+        used = used + '.' + n
+        try:
+            found = getattr(found, n)
+        except AttributeError:
+            __import__(used)
+            found = getattr(found, n)
+    return found
+
+
 def _create_formatters(cp):
     """Create and return formatters"""
     flist = cp.get("formatters", "keys")
@@ -104,7 +119,12 @@
             dfs = cp.get(sectname, "datefmt", 1)
         else:
             dfs = None
-        f = logging.Formatter(fs, dfs)
+        c = logging.Formatter
+        if "class" in opts:
+            class_name = cp.get(sectname, "class")
+            if class_name:
+                c = _resolve(class_name)
+        f = c(fs, dfs)
         formatters[form] = f
     return formatters
 


More information about the Python-checkins mailing list