drop entries from the top of stack to exclude the functions that retrieve the traceback
parent_class
str
None
sample implementations of stack tracing methods
# assert that the result of test_trace is of type FrameSummarylog = Logger(app_name="test traceback")class Foo: logger: Loggerdef__init__(self):self.logger = Logger(app_name=self.__class__.__name__)def test_traceback(self):returnself.logger.get_traceback().__dict__test_foo = Foo()test_foo.test_traceback()
{'traceback_stack': [<FrameSummary file /tmp/ipykernel_54263/2551220874.py, line 17 in <module>>,
<FrameSummary file /tmp/ipykernel_54263/2551220874.py, line 12 in test_traceback>],
'function_name': 'get_traceback',
'file_name': None,
'function_trail': '<module> -> test_traceback',
'parent_class': 'Logger',
'debug_traceback': False}
Sample implementation with a custom write_logs method
import pandas as pddef custom_write_logs_fn(logs):print("printing logs")return pd.DataFrame(logs)logger = Logger(app_name="test", output_fn=custom_write_logs_fn)def test_error():try:if1==1:raiseException("random error")exceptExceptionas e: logger.log_error(e)def double_test(): test_error()# record first errortest_error()# records second error nested inside double_test()double_test()logger.output_log()