wag-services-and-backend-la.../Commons/logger_functions.py

15 lines
500 B
Python

"""Utility functions for getting line numbers and file locations."""
from inspect import currentframe, getframeinfo, stack
def get_line_number_for_error() -> str:
"""Get the file name and line number of where an error occurred.
Returns:
str: A string in the format 'filename | line_number' showing where the error occurred
"""
caller = stack()[1] # Get the caller's frame
frame_info = getframeinfo(caller[0])
return f"{frame_info.filename} | {frame_info.lineno}"