summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2014-01-13 22:01:16 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2014-01-13 22:01:16 (GMT)
commit30e6a64e7675b16c5ba501d98de4702c468b134d (patch)
tree3c4d3b38e2782314f0459168fa1457a501b26836 /Lib/logging
parent936dfae2e22b5b58d01416ddf47218c20bfde5e6 (diff)
parent1fd1202072e198a7b3cf1254787aff3e3bf1c99e (diff)
downloadcpython-30e6a64e7675b16c5ba501d98de4702c468b134d.zip
cpython-30e6a64e7675b16c5ba501d98de4702c468b134d.tar.gz
cpython-30e6a64e7675b16c5ba501d98de4702c468b134d.tar.bz2
Closes #20242: Merged fix from 3.3.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 9b41b9d..bd9b994 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -390,10 +390,12 @@ class StringTemplateStyle(PercentStyle):
def format(self, record):
return self._tpl.substitute(**record.__dict__)
+BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
+
_STYLES = {
- '%': PercentStyle,
- '{': StrFormatStyle,
- '$': StringTemplateStyle
+ '%': (PercentStyle, BASIC_FORMAT),
+ '{': (StrFormatStyle, '{levelname}:{name}:{message}'),
+ '$': (StringTemplateStyle, '${levelname}:${name}:${message}'),
}
class Formatter(object):
@@ -458,7 +460,7 @@ class Formatter(object):
if style not in _STYLES:
raise ValueError('Style must be one of: %s' % ','.join(
_STYLES.keys()))
- self._style = _STYLES[style](fmt)
+ self._style = _STYLES[style][0](fmt)
self._fmt = self._style._fmt
self.datefmt = datefmt
@@ -1643,8 +1645,6 @@ Logger.manager = Manager(Logger.root)
# Configuration classes and functions
#---------------------------------------------------------------------------
-BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
-
def basicConfig(**kwargs):
"""
Do basic configuration for the logging system.
@@ -1718,9 +1718,12 @@ def basicConfig(**kwargs):
stream = kwargs.get("stream")
h = StreamHandler(stream)
handlers = [h]
- fs = kwargs.get("format", BASIC_FORMAT)
dfs = kwargs.get("datefmt", None)
style = kwargs.get("style", '%')
+ if style not in _STYLES:
+ raise ValueError('Style must be one of: %s' % ','.join(
+ _STYLES.keys()))
+ fs = kwargs.get("format", _STYLES[style][1])
fmt = Formatter(fs, dfs, style)
for h in handlers:
if h.formatter is None: