mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 12:34:17 +02:00
Merge pull request #22 from jlowin/logging-and-dotenv
add rich handler and dotenv loading for settings
This commit is contained in:
commit
d27f09f224
3 changed files with 14 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue