summaryrefslogtreecommitdiffstats
path: root/Lib/logging/__init__.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2014-01-13 21:59:56 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2014-01-13 21:59:56 (GMT)
commit1fd1202072e198a7b3cf1254787aff3e3bf1c99e (patch)
tree4012319a4d96feaad50150a0bde90da1d6989f8e /Lib/logging/__init__.py
parent66c9350a8932d41f2c34c0e8a511c20f4d7acb3e (diff)
downloadcpython-1fd1202072e198a7b3cf1254787aff3e3bf1c99e.zip
cpython-1fd1202072e198a7b3cf1254787aff3e3bf1c99e.tar.gz
cpython-1fd1202072e198a7b3cf1254787aff3e3bf1c99e.tar.bz2
Issue #20242: Fixed basicConfig() format strings for the alternative formatting styles.
Diffstat (limited to 'Lib/logging/__init__.py')
-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 7f94e39..9f436f3 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -388,10 +388,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):
@@ -456,7 +458,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
@@ -1629,8 +1631,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.
@@ -1704,9 +1704,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: