fix: log info (#965)

* fix log caller_info

* make env info beauty
This commit is contained in:
XianBW
2025-06-16 19:52:44 +08:00
committed by GitHub
parent 9165d64464
commit 90b0765561
3 changed files with 10 additions and 8 deletions
+6 -4
View File
@@ -20,7 +20,7 @@ from rdagent.core.utils import SingletonBaseClass, import_class
from .base import Storage
from .storage import FileStorage
from .utils import get_caller_info
from .utils import LogColors, get_caller_info
class RDAgentLog(SingletonBaseClass):
@@ -106,15 +106,17 @@ class RDAgentLog(SingletonBaseClass):
return pid_chain
def log_object(self, obj: object, *, tag: str = "") -> None:
caller_info = get_caller_info()
caller_info = get_caller_info(level=2)
tag = f"{self._tag}.{tag}.{self.get_pids()}".strip(".")
for storage in [self.storage] + self.other_storages:
logp = storage.log(obj, tag=tag)
logger.patch(lambda r: r.update(caller_info)).info(f"Log object to [{storage}], uri: {logp}")
logger.patch(lambda r: r.update(caller_info)).info(
f"{LogColors.GRAY}Log object to [{storage}], uri: {logp}{LogColors.END}"
)
def _log(self, level: str, msg: str, *, tag: str = "", raw: bool = False) -> None:
caller_info = get_caller_info()
caller_info = get_caller_info(level=3)
tag = f"{self._tag}.{tag}.{self.get_pids()}".strip(".")
if raw:
+2 -2
View File
@@ -66,11 +66,11 @@ class CallerInfo(TypedDict):
name: Optional[str]
def get_caller_info() -> CallerInfo:
def get_caller_info(level: int = 2) -> CallerInfo:
# Get the current stack information
stack = inspect.stack()
# The second element is usually the caller's information
caller_info = stack[2]
caller_info = stack[level]
frame = caller_info[0]
info: CallerInfo = {
"line": caller_info.lineno,
+2 -2
View File
@@ -469,11 +469,11 @@ class LocalEnv(Env[ASpecificLocalConf]):
print(Rule("[bold green]LocalEnv Logs Begin[/bold green]", style="dark_orange"))
table = Table(title="Run Info", show_header=False)
table.add_column("Key", style="bold cyan")
table.add_column("Value", style="bold magenta")
table.add_column("Value", style="bold magenta", no_wrap=True)
table.add_row("Entry", entry)
table.add_row("Local Path", local_path or "")
table.add_row("Env", "\n".join(f"{k}:{v}" for k, v in env.items()))
table.add_row("Volumes", "\n".join(f"{k}:{v}" for k, v in volumes.items()))
table.add_row("Volumes", "\n".join(f"{k}:\n {v}" for k, v in volumes.items()))
print(table)
cwd = Path(local_path).resolve() if local_path else None