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

Skip to content

Commit 260ce43

Browse files
committed
Propagate exceptions from shutdown() if raiseExceptions is not set.
Added 'extra' keyword argument handling to logging calls, as discussed on python-dev.
1 parent 1eb77a5 commit 260ce43

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

Lib/logging/__init__.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,14 +1053,20 @@ def findCaller(self):
10531053
continue
10541054
return filename, f.f_lineno, co.co_name
10551055

1056-
def makeRecord(self, name, level, fn, lno, msg, args, exc_info):
1056+
def makeRecord(self, name, level, fn, lno, msg, args, exc_info, extra=None):
10571057
"""
10581058
A factory method which can be overridden in subclasses to create
10591059
specialized LogRecords.
10601060
"""
1061-
return LogRecord(name, level, fn, lno, msg, args, exc_info)
1061+
rv = LogRecord(name, level, fn, lno, msg, args, exc_info)
1062+
if extra:
1063+
for key in extra:
1064+
if (key in ["message", "asctime"]) or (key in rv.__dict__):
1065+
raise KeyError("Attempt to overwrite %r in LogRecord" % key)
1066+
rv.__dict__[key] = extra[key]
1067+
return rv
10621068

1063-
def _log(self, level, msg, args, exc_info=None):
1069+
def _log(self, level, msg, args, exc_info=None, extra=None):
10641070
"""
10651071
Low-level logging routine which creates a LogRecord and then calls
10661072
all the handlers of this logger to handle the record.
@@ -1072,7 +1078,7 @@ def _log(self, level, msg, args, exc_info=None):
10721078
if exc_info:
10731079
if type(exc_info) != types.TupleType:
10741080
exc_info = sys.exc_info()
1075-
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info)
1081+
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, extra)
10761082
self.handle(record)
10771083

10781084
def handle(self, record):
@@ -1324,12 +1330,14 @@ def shutdown():
13241330
"""
13251331
for h in _handlerList[:]: # was _handlers.keys():
13261332
#errors might occur, for example, if files are locked
1327-
#we just ignore them
1333+
#we just ignore them if raiseExceptions is not set
13281334
try:
13291335
h.flush()
13301336
h.close()
13311337
except:
1332-
pass
1338+
if raiseExceptions:
1339+
raise
1340+
#else, swallow
13331341

13341342
#Let's try and shutdown automatically on application exit...
13351343
try:

0 commit comments

Comments
 (0)