diff --git a/pyproject.toml b/pyproject.toml index 26008a8..bfb44f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ namespaces = true # ----------------------------------------- Project Metadata ------------------------------------- # [project] -version = "0.0.0.dev37" +version = "0.0.0.dev38" name = "LoggerMan" dependencies = [ "MDit == 0.0.0.dev12", diff --git a/src/loggerman/logger.py b/src/loggerman/logger.py index 45c07a7..56af497 100644 --- a/src/loggerman/logger.py +++ b/src/loggerman/logger.py @@ -7,6 +7,7 @@ import sys as _sys import traceback as _traceback from functools import wraps as _wraps +from pathlib import Path as _Path import actionman as _actionman import mdit as _mdit @@ -708,11 +709,19 @@ def _get_github_annotation_type(level: LogLevel) -> Literal["notice", "warning", def _get_caller_name(stack_up: int = 0) -> str: stack = _inspect.stack() # The caller is the second element in the stack list - caller_frame = stack[2 + stack_up] - module = _inspect.getmodule(caller_frame[0]) - module_name = module.__name__ if module else "" + caller_frame = stack[stack_up + 1] + caller_module = _inspect.getmodule(caller_frame.frame) + if caller_module: + caller_module_name = caller_module.__name__ + else: + caller_filename = caller_frame.filename + caller_filepath = _Path(caller_filename) + caller_module_name = caller_filepath.stem # Get the function or method name func_name = caller_frame.function # Combine them to get a fully qualified name - fully_qualified_name = f"{module_name}.{func_name}" + if func_name == "": + fully_qualified_name = f"{caller_module_name}:{caller_frame.lineno}" + else: + fully_qualified_name = f"{caller_module_name}.{func_name}" return fully_qualified_name