diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2006-01-20 18:28:03 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2006-01-20 18:28:03 (GMT) |
commit | 7a7160bd0c6b43b2b0705f43a32a4a7fae2127cd (patch) | |
tree | c8045243a729185caef6feda13843c436353bb2d | |
parent | 81cdb4ebe1e8062168f44f12c80e0426344add31 (diff) | |
download | cpython-7a7160bd0c6b43b2b0705f43a32a4a7fae2127cd.zip cpython-7a7160bd0c6b43b2b0705f43a32a4a7fae2127cd.tar.gz cpython-7a7160bd0c6b43b2b0705f43a32a4a7fae2127cd.tar.bz2 |
Added the ability to specify a class attribute in Formatter configuration. Contributed by Shane Hathaway.
-rw-r--r-- | Lib/logging/config.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 37d8775..5adfe4d 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -86,6 +86,21 @@ def fileConfig(fname, defaults=None): 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 @@ def _create_formatters(cp): 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 |