Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1fd12020
Commit
1fd12020
authored
Jan 13, 2014
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20242: Fixed basicConfig() format strings for the alternative formatting styles.
parent
66c9350a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
7 deletions
+29
-7
Lib/logging/__init__.py
Lib/logging/__init__.py
+10
-7
Lib/test/test_logging.py
Lib/test/test_logging.py
+16
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/logging/__init__.py
View file @
1fd12020
...
...
@@ -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
:
...
...
Lib/test/test_logging.py
View file @
1fd12020
...
...
@@ -3337,6 +3337,22 @@ class BasicConfigTest(unittest.TestCase):
# level is not explicitly set
self.assertEqual(logging.root.level, self.original_logging_level)
def test_strformatstyle(self):
with captured_stdout() as output:
logging.basicConfig(stream=sys.stdout, style="
{
")
logging.error("
Log
an
error
")
sys.stdout.seek(0)
self.assertEqual(output.getvalue().strip(),
"
ERROR
:
root
:
Log
an
error
")
def test_stringtemplatestyle(self):
with captured_stdout() as output:
logging.basicConfig(stream=sys.stdout, style="
$
")
logging.error("
Log
an
error
")
sys.stdout.seek(0)
self.assertEqual(output.getvalue().strip(),
"
ERROR
:
root
:
Log
an
error
")
def test_filename(self):
logging.basicConfig(filename='test.log')
...
...
Misc/NEWS
View file @
1fd12020
...
...
@@ -43,6 +43,9 @@ Core and Builtins
Library
-------
- Issue #20242: Fixed basicConfig() format strings for the alternative
formatting styles. Thanks to kespindler for the bug report and patch.
- Issues #20206 and #5803: Fix edge case in email.quoprimime.encode where it
truncated lines ending in a character needing encoding but no newline by
using a more efficient algorithm that doesn'
t
have
the
bug
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment