Skip to content

Commit

Permalink
get func name
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbowen committed Dec 10, 2024
1 parent 8a9d4ec commit cfc10e1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/logger_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import json
import logging

Expand All @@ -11,7 +12,7 @@ def format(self, record):
"timestamp": self.formatTime(record),
"level": record.levelname,
"module": record.module,
"function": record.funcName,
"function": self.get_original_function_name(record),
"line_number": record.lineno,
}

Expand All @@ -34,6 +35,12 @@ def format(self, record):

return json.dumps(log_record)

def get_original_function_name(self, record):
for frame in inspect.stack():
if frame.function == record.funcName:
return frame.function
return record.funcName


def setup_logger(name, level, formatter):
"""Helper function to set up a logger."""
Expand Down

0 comments on commit cfc10e1

Please sign in to comment.