Merge pull request #22 from jlowin/logging-and-dotenv

add rich handler and dotenv loading for settings
This commit is contained in:
nate nowack 2024-11-30 19:24:58 -06:00 committed by GitHub
commit d27f09f224
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 9 deletions

View file

@ -13,7 +13,7 @@ from typing_extensions import Annotated
from ..utilities.logging import get_logger
from . import claude
logger = get_logger(__name__)
logger = get_logger("cli")
app = typer.Typer(
name="fastmcp",
@ -352,7 +352,7 @@ def install(
with_packages=with_packages,
force=force,
):
print(f"Successfully installed {name} in Claude app")
logger.info(f"Successfully installed {name} in Claude app")
else:
print(f"Failed to install {name} in Claude app")
logger.error(f"Failed to install {name} in Claude app")
sys.exit(1)

View file

@ -53,7 +53,11 @@ class Settings(BaseSettings):
For example, FASTMCP_DEBUG=true will set debug=True.
"""
model_config: SettingsConfigDict = SettingsConfigDict(env_prefix="FASTMCP_")
model_config: SettingsConfigDict = SettingsConfigDict(
env_prefix="FASTMCP_",
env_file=".env",
extra="ignore",
)
# Server settings
debug: bool = False

View file

@ -3,15 +3,17 @@
import logging
from typing import Literal
from rich.logging import RichHandler
def get_logger(name: str) -> logging.Logger:
"""Get a logger nested under FastMCP namespace.
Args:
name: The name of the logger, which will be prefixed with 'FastMCP.'
name: the name of the logger, which will be prefixed with 'FastMCP.'
Returns:
A configured logger instance
a configured logger instance
"""
return logging.getLogger(f"FastMCP.{name}")
@ -22,9 +24,8 @@ def configure_logging(
"""Configure logging for FastMCP.
Args:
level: The log level to use
level: the log level to use
"""
logging.basicConfig(
level=level,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=level, format="%(message)s", handlers=[RichHandler(rich_tracebacks=True)]
)