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

Skip to content

Commit ed1992f

Browse files
committed
Added function name to LogRecord.
1 parent 260ce43 commit ed1992f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Lib/logging/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ class LogRecord:
203203
the source line where the logging call was made, and any exception
204204
information to be logged.
205205
"""
206-
def __init__(self, name, level, pathname, lineno, msg, args, exc_info):
206+
def __init__(self, name, level, pathname, lineno,
207+
msg, args, exc_info, func):
207208
"""
208209
Initialize a logging record with interesting information.
209210
"""
@@ -238,6 +239,7 @@ def __init__(self, name, level, pathname, lineno, msg, args, exc_info):
238239
self.exc_info = exc_info
239240
self.exc_text = None # used to cache the traceback text
240241
self.lineno = lineno
242+
self.funcName = func
241243
self.created = ct
242244
self.msecs = (ct - long(ct)) * 1000
243245
self.relativeCreated = (self.created - _startTime) * 1000
@@ -283,7 +285,7 @@ def makeLogRecord(dict):
283285
a socket connection (which is sent as a dictionary) into a LogRecord
284286
instance.
285287
"""
286-
rv = LogRecord(None, None, "", 0, "", (), None)
288+
rv = LogRecord(None, None, "", 0, "", (), None, None)
287289
rv.__dict__.update(dict)
288290
return rv
289291

@@ -318,6 +320,7 @@ class Formatter:
318320
%(module)s Module (name portion of filename)
319321
%(lineno)d Source line number where the logging call was issued
320322
(if available)
323+
%(funcName)s Function name
321324
%(created)f Time when the LogRecord was created (time.time()
322325
return value)
323326
%(asctime)s Textual time when the LogRecord was created
@@ -1053,12 +1056,12 @@ def findCaller(self):
10531056
continue
10541057
return filename, f.f_lineno, co.co_name
10551058

1056-
def makeRecord(self, name, level, fn, lno, msg, args, exc_info, extra=None):
1059+
def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None):
10571060
"""
10581061
A factory method which can be overridden in subclasses to create
10591062
specialized LogRecords.
10601063
"""
1061-
rv = LogRecord(name, level, fn, lno, msg, args, exc_info)
1064+
rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
10621065
if extra:
10631066
for key in extra:
10641067
if (key in ["message", "asctime"]) or (key in rv.__dict__):
@@ -1078,7 +1081,7 @@ def _log(self, level, msg, args, exc_info=None, extra=None):
10781081
if exc_info:
10791082
if type(exc_info) != types.TupleType:
10801083
exc_info = sys.exc_info()
1081-
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, extra)
1084+
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
10821085
self.handle(record)
10831086

10841087
def handle(self, record):

0 commit comments

Comments
 (0)