Skip to content

Commit 277b43c

Browse files
committed
Release v0.1.1
Delegate caller name inference to `pkgdata`
1 parent 72b3cc6 commit 277b43c

2 files changed

Lines changed: 6 additions & 28 deletions

File tree

pkg/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ namespaces = true
1717
# ----------------------------------------- Project Metadata -------------------------------------
1818
#
1919
[project]
20-
version = "0.1.0"
20+
version = "0.1.1"
2121
name = "LoggerMan"
2222
dependencies = [
2323
"MDit >=0.1,<0.2",
2424
"PySerials >=0.1,<0.2",
2525
"ActionMan >=0.1,<0.2",
2626
"ProtocolMan >=0.1,<0.2",
2727
"ExceptionMan >=0.1,<0.2",
28+
"pkgdata >=0.1.2,<0.2",
2829
"pydantic",
2930
"rich",
3031
]

pkg/src/loggerman/logger.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from enum import Enum as _Enum
44
import datetime as _datetime
55
from typing import NamedTuple as _NamedTuple, Sequence as _Sequence, TYPE_CHECKING as _TYPE_CHECKING
6-
import inspect as _inspect
76
import sys as _sys
87
import traceback as _traceback
98
from functools import wraps as _wraps, partial as _partial
@@ -13,14 +12,13 @@
1312
import actionman as _actionman
1413
import mdit as _mdit
1514
from exceptionman import Traceback as _Traceback
15+
import pkgdata as _pkgdata
1616
import pyserials as _ps
1717
import rich
18-
import rich.traceback
1918
import rich._inspect
2019
import rich.pretty
2120
import rich.panel
2221
import rich.box
23-
import rich.markdown
2422
import rich.text
2523

2624
from loggerman import style as _style
@@ -30,7 +28,7 @@
3028
from types import ModuleType, TracebackType
3129
from typing import Literal, Sequence, Callable, Type, Iterable, Any
3230
from protocolman import Stringable
33-
from mdit.protocol import MDTargetConfig, RichTargetConfig, ContainerContentInputType
31+
from mdit.protocol import ContainerContentInputType
3432
from mdit import MDContainer
3533
from loggerman.style import LogLevelStyle
3634
from loggerman.protocol import Serializable
@@ -457,7 +455,7 @@ def log(
457455
stack_up: int = 0,
458456
):
459457
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))
461459
if self._list_entries and self._curr_list_key is None:
462460
self._curr_list_key = self._doc.current_section.body.append(
463461
content=_mdit.element.ordered_list(
@@ -693,7 +691,7 @@ def _get_sig(self, level: LogLevelStyle, stack_up: int = 0) -> _mdit.MDContainer
693691
signature = []
694692
for sig in level.signature:
695693
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)
697695
signature.append(_mdit.inline_container(self._prefix_caller_name, _mdit.element.code_span(caller)))
698696
if sig == "time":
699697
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",
742740
LogLevel.CRITICAL: "error",
743741
}
744742
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

Comments
 (0)