mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 22:17:35 +00:00
Fix logging
This commit is contained in:
1 parent
6927559e93
commit
6956012fa2
2 files changed
+15
-12
No files matched your search
+10
-11
@@ -159,18 +159,17 @@ class Tool(Component):
|
||||
raise Exception(f"Missing docstring for {self}")
|
||||
return docstring
|
||||
|
||||
@staticmethod
|
||||
def _log_tool_application(frame: Any) -> None:
|
||||
def _log_tool_application(self, frame: Any) -> None:
|
||||
params = {}
|
||||
tool_name = None
|
||||
for name, value in frame.f_locals.items():
|
||||
if name == "ctx":
|
||||
ignored_params = {"self", "log_call", "catch_exceptions", "args", "apply_fn"}
|
||||
for param, value in frame.f_locals.items():
|
||||
if param in ignored_params:
|
||||
continue
|
||||
if name.endswith("Tool"):
|
||||
tool_name = name
|
||||
continue
|
||||
params[name] = value
|
||||
log.info(f"{tool_name}: {dict_string(params)}")
|
||||
if param == "kwargs":
|
||||
params.update(value)
|
||||
else:
|
||||
params[param] = value
|
||||
log.info(f"{self.get_name()}: {dict_string(params)}")
|
||||
|
||||
@staticmethod
|
||||
def _limit_length(result: str, max_answer_chars: int) -> str:
|
||||
@@ -200,7 +199,7 @@ class Tool(Component):
|
||||
log.error(f"Error executing tool: {e}", exc_info=e)
|
||||
result = msg
|
||||
if log_call:
|
||||
log.info("Result: {}")
|
||||
log.info(f"Result: {result}")
|
||||
return result
|
||||
|
||||
|
||||
|
||||
+5
-1
@@ -6,6 +6,7 @@ import sys
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
from dataclasses import dataclass
|
||||
from logging import Formatter, Logger, StreamHandler
|
||||
|
||||
from mcp.server.fastmcp import server
|
||||
from mcp.server.fastmcp.server import FastMCP, Settings
|
||||
@@ -23,7 +24,10 @@ LOG_LEVEL = logging.INFO
|
||||
|
||||
def configure_logging(*args, **kwargs) -> None: # type: ignore
|
||||
# configure logging to stderr (will be captured by Claude Desktop); stdio is the MCP communication stream and cannot be used!
|
||||
logging.basicConfig(level=LOG_LEVEL, stream=sys.stderr, format=LOG_FORMAT)
|
||||
Logger.root.setLevel(LOG_LEVEL)
|
||||
handler = StreamHandler(stream=sys.stderr)
|
||||
handler.formatter = Formatter(LOG_FORMAT)
|
||||
Logger.root.addHandler(handler)
|
||||
|
||||
|
||||
# patch the logging configuration function in fastmcp, because it's hard-coded and broken
|
||||
|
||||
Reference in new issue
Block a user