|
3 | 3 | from enum import Enum as _Enum |
4 | 4 | import datetime as _datetime |
5 | 5 | from typing import NamedTuple as _NamedTuple, Sequence as _Sequence, TYPE_CHECKING as _TYPE_CHECKING |
6 | | -import inspect as _inspect |
7 | 6 | import sys as _sys |
8 | 7 | import traceback as _traceback |
9 | 8 | from functools import wraps as _wraps, partial as _partial |
|
13 | 12 | import actionman as _actionman |
14 | 13 | import mdit as _mdit |
15 | 14 | from exceptionman import Traceback as _Traceback |
| 15 | +import pkgdata as _pkgdata |
16 | 16 | import pyserials as _ps |
17 | 17 | import rich |
18 | | -import rich.traceback |
19 | 18 | import rich._inspect |
20 | 19 | import rich.pretty |
21 | 20 | import rich.panel |
22 | 21 | import rich.box |
23 | | -import rich.markdown |
24 | 22 | import rich.text |
25 | 23 |
|
26 | 24 | from loggerman import style as _style |
|
30 | 28 | from types import ModuleType, TracebackType |
31 | 29 | from typing import Literal, Sequence, Callable, Type, Iterable, Any |
32 | 30 | from protocolman import Stringable |
33 | | - from mdit.protocol import MDTargetConfig, RichTargetConfig, ContainerContentInputType |
| 31 | + from mdit.protocol import ContainerContentInputType |
34 | 32 | from mdit import MDContainer |
35 | 33 | from loggerman.style import LogLevelStyle |
36 | 34 | from loggerman.protocol import Serializable |
@@ -457,7 +455,7 @@ def log( |
457 | 455 | stack_up: int = 0, |
458 | 456 | ): |
459 | 457 | if self._out_of_section: |
460 | | - self.section(title=self._get_caller_name(stack_up+1)) |
| 458 | + self.section(title=_pkgdata.get_caller_name(stack_up=stack_up+1, lineno=True)) |
461 | 459 | if self._list_entries and self._curr_list_key is None: |
462 | 460 | self._curr_list_key = self._doc.current_section.body.append( |
463 | 461 | content=_mdit.element.ordered_list( |
@@ -693,7 +691,7 @@ def _get_sig(self, level: LogLevelStyle, stack_up: int = 0) -> _mdit.MDContainer |
693 | 691 | signature = [] |
694 | 692 | for sig in level.signature: |
695 | 693 | if sig == "caller_name": |
696 | | - caller = self._get_caller_name(stack_up=stack_up + 1) |
| 694 | + caller = _pkgdata.get_caller_name(stack_up=stack_up+1, lineno=True) |
697 | 695 | signature.append(_mdit.inline_container(self._prefix_caller_name, _mdit.element.code_span(caller))) |
698 | 696 | if sig == "time": |
699 | 697 | timestamp = _datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
@@ -742,24 +740,3 @@ def _get_github_annotation_type(level: LogLevel) -> Literal["notice", "warning", |
742 | 740 | LogLevel.CRITICAL: "error", |
743 | 741 | } |
744 | 742 | return mapping[level] if level in mapping else None |
745 | | - |
746 | | - @staticmethod |
747 | | - def _get_caller_name(stack_up: int = 0) -> str: |
748 | | - stack = _inspect.stack() |
749 | | - # The caller is the second element in the stack list |
750 | | - caller_frame = stack[stack_up + 1] |
751 | | - caller_module = _inspect.getmodule(caller_frame.frame) |
752 | | - if caller_module: |
753 | | - caller_module_name = caller_module.__name__ |
754 | | - else: |
755 | | - caller_filename = caller_frame.filename |
756 | | - caller_filepath = _Path(caller_filename) |
757 | | - caller_module_name = caller_filepath.stem |
758 | | - # Get the function or method name |
759 | | - func_name = caller_frame.function |
760 | | - # Combine them to get a fully qualified name |
761 | | - if func_name == "<module>": |
762 | | - fully_qualified_name = f"{caller_module_name}:{caller_frame.lineno}" |
763 | | - else: |
764 | | - fully_qualified_name = f"{caller_module_name}.{func_name}" |
765 | | - return fully_qualified_name |
0 commit comments