Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ed315a

Browse files
committed
Changed handling of args in LogRecord.__init__.
1 parent c64aab8 commit 4ed315a

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/logging/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
__author__ = "Vinay Sajip <[email protected]>"
3838
__status__ = "beta"
39-
__version__ = "0.4.9.5"
40-
__date__ = "02 October 2004"
39+
__version__ = "0.4.9.6"
40+
__date__ = "20 October 2004"
4141

4242
#---------------------------------------------------------------------------
4343
# Miscellaneous module data
@@ -191,6 +191,21 @@ def __init__(self, name, level, pathname, lineno, msg, args, exc_info):
191191
ct = time.time()
192192
self.name = name
193193
self.msg = msg
194+
#
195+
# The following statement allows passing of a dictionary as a sole
196+
# argument, so that you can do something like
197+
# logging.debug("a %(a)d b %(b)s", {'a':1, 'b':2})
198+
# Suggested by Stefan Behnel.
199+
# Note that without the test for args[0], we get a problem because
200+
# during formatting, we test to see if the arg is present using
201+
# 'if self.args:'. If the event being logged is e.g. 'Value is %d'
202+
# and if the passed arg fails 'if self.args:' then no formatting
203+
# is done. For example, logger.warn('Value is %d', 0) would log
204+
# 'Value is %d' instead of 'Value is 0'.
205+
# For the use case of passing a dictionary, this should not be a
206+
# problem.
207+
if args and (len(args) == 1) and args[0]:
208+
args = args[0]
194209
self.args = args
195210
self.levelname = getLevelName(level)
196211
self.levelno = level

0 commit comments

Comments
 (0)