Args: depth (int): Depth of caller conext, use 0 for caller depth. Default value: 0. Returns: str: module name of the caller
(depth=0)
| 10 | |
| 11 | |
| 12 | def get_caller_name(depth=0): |
| 13 | """ |
| 14 | Args: |
| 15 | depth (int): Depth of caller conext, use 0 for caller depth. Default value: 0. |
| 16 | |
| 17 | Returns: |
| 18 | str: module name of the caller |
| 19 | """ |
| 20 | # the following logic is a little bit faster than inspect.stack() logic |
| 21 | frame = inspect.currentframe().f_back |
| 22 | for _ in range(depth): |
| 23 | frame = frame.f_back |
| 24 | |
| 25 | return frame.f_globals["__name__"] |
| 26 | |
| 27 | |
| 28 | class StreamToLoguru: |