diff --git a/src/grist_mcp/logging.py b/src/grist_mcp/logging.py index f5af822..22f7ecd 100644 --- a/src/grist_mcp/logging.py +++ b/src/grist_mcp/logging.py @@ -104,3 +104,8 @@ def format_tool_log( line += f"\n {error_message}" return line + + +def get_logger(name: str) -> logging.Logger: + """Get a child logger under the grist_mcp namespace.""" + return logging.getLogger(f"grist_mcp.{name}") diff --git a/tests/unit/test_logging.py b/tests/unit/test_logging.py index 4a3d46d..babb127 100644 --- a/tests/unit/test_logging.py +++ b/tests/unit/test_logging.py @@ -150,3 +150,21 @@ class TestSetupLogging: logger = logging.getLogger("grist_mcp") assert logger.level == logging.INFO + + +class TestGetLogger: + def test_returns_child_logger(self): + from grist_mcp.logging import get_logger + + logger = get_logger("server") + assert logger.name == "grist_mcp.server" + + def test_inherits_parent_level(self, monkeypatch): + monkeypatch.setenv("LOG_LEVEL", "WARNING") + + from grist_mcp.logging import setup_logging, get_logger + setup_logging() + + logger = get_logger("test") + # Child inherits from parent when level is NOTSET + assert logger.getEffectiveLevel() == logging.WARNING