-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Summary
aden_tools currently does not have a shared logging standard. Errors are correctly returned to callers, but maintainers don’t have consistent runtime logs to help with debugging and operational visibility—especially important for MCP STDIO, where stdout must remain clean for JSON-RPC.
We also ran into a practical issue during development: Python logging can raise a runtime KeyError when extra contains reserved LogRecord keys (for example extra={"name": ...}), which can unexpectedly crash otherwise normal error paths.
Proposal
-
Add a small, centralized logging helper:
configure_logging()(safe to call multiple times)get_logger()
-
Default all logs to stderr (STDIO / JSON-RPC safe).
-
Allow basic configuration via environment variables:
ADEN_TOOLS_LOG_LEVEL(default:INFO)ADEN_TOOLS_LOG_FORMAT
-
Standardize safe structured log metadata:
- Avoid reserved
LogRecordfields such asname,message, andasctime.
- Avoid reserved
-
Add a lightweight test to ensure:
- Logging initialization is idempotent (no duplicate handlers).
Example (real issue → safe pattern)
Before
logger.warning(
"pdf_read file not found",
extra={"name": path.name}
)This can raise a runtime KeyError due to LogRecord field collisions.
After
logger.warning(
"pdf_read file not found",
extra={"file_name": path.name}
)Uses a neutral metadata key and avoids collisions.
Test plan
cd tools
python3 -m pip install -e ".[dev]"
python3 -m pytest tests