Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit ea0b5a4

Browse files
committed
Populate the funcName and filename fields of the LogRecord with the correct values. The funcName field is propagated unchanged by appengine logging. The filename field is not currently used anywhere, but its value is currently inconsistent with pathname for logpoints.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=144147325
1 parent 513b8aa commit ea0b5a4

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/googleclouddebugger/capture_collector.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,34 @@ def filter(self, record):
104104
# particular invocation came from our logging code.
105105
if record.pathname != inspect.currentframe().f_code.co_filename:
106106
return True
107-
pathname, lineno = GetLoggingFileAndLine()
108-
if pathname and lineno:
107+
pathname, lineno, func_name = GetLoggingLocation()
108+
if pathname:
109109
record.pathname = pathname
110+
record.filename = os.path.basename(pathname)
110111
record.lineno = lineno
112+
record.funcName = func_name
111113
return True
112114

113115

114-
def GetLoggingFileAndLine():
115-
"""Search for and return the file and line number from the log collector."""
116+
def GetLoggingLocation():
117+
"""Search for and return the file and line number from the log collector.
118+
119+
Returns:
120+
(pathname, lineno, func_name) The full path, line number, and function name
121+
for the logpoint location.
122+
"""
116123
frame = inspect.currentframe()
117124
this_file = frame.f_code.co_filename
118125
frame = frame.f_back
119126
while frame:
120127
if this_file == frame.f_code.co_filename:
121-
if 'cdbg_logging_pathname' in frame.f_locals:
122-
return (frame.f_locals['cdbg_logging_pathname'],
123-
frame.f_locals.get('cdbg_logging_lineno', None))
128+
if 'cdbg_logging_location' in frame.f_locals:
129+
ret = frame.f_locals['cdbg_logging_location']
130+
if len(ret) != 3:
131+
return (None, None, None)
132+
return ret
124133
frame = frame.f_back
125-
return (None, None)
134+
return (None, None, None)
126135

127136

128137
def SetLogger(logger):
@@ -611,11 +620,11 @@ def Log(self, frame):
611620
self._definition.get('logMessageFormat', ''),
612621
self._EvaluateExpressions(frame))
613622

614-
cdbg_logging_pathname = NormalizePath(frame.f_code.co_filename)
615-
cdbg_logging_lineno = frame.f_lineno
623+
cdbg_logging_location = (
624+
NormalizePath(frame.f_code.co_filename), frame.f_lineno,
625+
frame.f_code.co_name)
616626
self._log_message('LOGPOINT: ' + message)
617-
del cdbg_logging_pathname
618-
del cdbg_logging_lineno
627+
del cdbg_logging_location
619628
return None
620629

621630
def _EvaluateExpressions(self, frame):

0 commit comments

Comments
 (0)